Web Hosting Talk







View Full Version : PHP - Sending Double Email On Submission


LBGA
02-15-2005, 10:06 PM
Hello,

I designed a PHP form mail script and I do not see the problem or what is causing the script to send me duplicate emails at the same time. Can you please advise and tell me where the problem is?


<? if(!$action) { ?>

<form method="POST" onSubmit="submitonce(this)">
<input type="hidden" name="action" value="Send">

<div align="center">
<center>
<table border="0">
<tr>
<td align="right"><font face="Verdana" size="2"><b>Name:</b></font></td>
<td><input type="text" name="Name" size="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Email:</b></font></td>
<td><input type="text" name="Email" size="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Server IP Address:</b></font></td>
<td><input type="text" name="ServerIP" size="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Server Name:</b></font></td>
<td><input type="text" name="Server" size="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Root Username:</b></font></td>
<td><input type="text" name="Username" size="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Root Password:</b></font></td>
<td><input type="password" name="Pass" size="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Support Type:</b></font></td>
<td><select size="1" name="Type">
<option>Choose One</option>
<option value="Dedicated Server">Dedicated Server</option>
<option value="Co-Location">Co-Location</option>
<option value="Reboot Request">Reboot Request</option>
</select></td>
</tr>
<tr>
<td align="right"><font face="Verdana" size="2"><b>Problem:</b></font></td>
<td><textarea rows="3" name="Problem" cols="30"></textarea></td>
</tr>
</table>
</center>
</div>
<p align="center"><input type="submit" value="Send Request" name="Submit">
<input type="reset" value="Reset"></p>
</form>
<? } ?>

<? if($action=="Send") { ?>

<?

$time = date("h:i:s A T");
$date = date("mdY");
$date2 = date("m-d-Y");
$randomnumber = rand(100,999);
$ID = "DSR" . $date . "-" .$randomnumber;

$ToName="Host Flight - Dedicated Support";
$ToEmail="dedicated@hostflight.com";
$Company="Host Flight.com";
$Mailer="Host Flight.com Dedicated Support Mailer";
$FileName = "ded_request.txt";
$SendEmail="Yes";
$Logging="No";
$IP = "$_SERVER[REMOTE_ADDR]";
$Browser = "$_SERVER[HTTP_USER_AGENT]";

$Message="
Customer Information
____________________
Name: $Name
Email: $Email

Server Information
__________________
Server IP: $ServerIP
Server Name: $Server
Root Username: $Username
Root Password: $Pass

Support Information
___________________
Support Type: $Type
Problem: $Problem


User IP Address: $IP
User Browser: $Browser
";

if ($Logging == "Yes") {
$FilePointer = fopen ($FileName, "a");
fwrite ($FilePointer, "- $ID|$IP|$Name|$Email|$Phone|$Calltime|$date|$time\n");
fclose ($FilePointer);
chmod ("$FileName", 0777);
}

$Subject="Dedicated Server Support Request - $Type [$Server]";
$Headers .= "From: ".$Name." <".$Email.">\r\n";
$Headers .= "To: ".$ToName." <".$ToEmail.">\r\n";
$Headers .= "X-Mailer: $Mailer";

if ($SendEmail == "Yes") {
mail($ToEmail, $Subject, $Message, $Headers);
}

print "Your dedicated server support request has been sent. A $Company dedicated server support representative will be in contact with you shortly. Thank you for using our Dedicated Server Support Request form.
<br><br>
<b>You Have Sent The Following Information:</b>
<br><br>
<b>Request ID:</b> $ID <br>
<b>Customer Name:</b> $Name <br>
<b>Email:</b> $Email <br>
<b>Server IP:</b> $ServerIP <br>
<b>Server Name:</b> $Server <br>
<b>Username:</b> $Username <br>
<b>Password:</b> ****** (Masked For Security Purposes) <br>
<b>Support Type:</b> $Type <br>
<b>Problem:</b> $Problem <br>
<b>Date Request Sent:</b> $date2 <br>
<b>Time Request Sent:</b> $time <br>
";
?>

<? } ?>


Please respond directly to this message, in case other's have this same problem. I don't see where this is occuring at. Can someone else please view this and let me know?

Thank you,

joshuayip
02-16-2005, 12:15 AM
Some proposed solution
1. You can try to do an inline debugging to see the execution path of your code.
2. You can try to use action attribute on the form tag to call the script, instead of javascript on submit. I am having a feeling that might be causing it.

Joshua

LBGA
02-16-2005, 12:34 AM
The javascript, that you see in the form tag at the top, has a part to it, that is in the head tag, and all this does is have the form do a 1 time submission, and it makes the submit button not clickable anymore, so that the form can not be submitted twice.

What do you mean by inline debugging? I don't know how to do that... Can you please advise?

joshuayip
02-16-2005, 12:37 AM
Funny. I ran your script on my server, it only sends me the email once,

You want me to setup your address and you can try access it from my server?

Joshua

LBGA
02-16-2005, 12:41 AM
Josh,

Yea. Let's see what it does. Maybe I have a forwarder or something setup in the control panel that is double sending the email to me.

Regards,
Larry

joshuayip
02-16-2005, 12:46 AM
Here, have a go at it.

ivoxone dot com/ivox/support.php

I didnt modify the code, just put in the html , body tags,

probably you are right, the problem with the forwarder

check in there then :)

Joshua

LBGA
02-16-2005, 12:54 AM
Originally posted by joshuayip
Here, have a go at it.

ivoxone dot com/ivox/support.php

I didnt modify the code, just put in the html , body tags,

probably you are right, the problem with the forwarder

check in there then :)

Joshua

I'm getting an error:

Parse error: parse error, unexpected T_VARIABLE in /home/ivoxone/public_html/ivox/support.php on line 73

Please check this... and let me know when you have it fixed.

joshuayip
02-16-2005, 01:51 AM
Hi Larry,

Please have a go. I changed it to your email

Joshua

mitchlrm
02-16-2005, 01:53 AM
You have a "To: " in $Headers and also referenced in the Mail command. This might be creating duplicate "To:" headers and therefore duplicate emails. Take out the line in the headers.

Mitch

joshuayip
02-16-2005, 02:04 AM
That doesnt happen to me . I got one email when I ran his script

Joshua

LBGA
02-16-2005, 09:51 AM
There is something wrong with the email address of dedicated@hostflight.com - I changed the email to support@hostflight.com and the script only submitted to me, 1 email. I have checked the Help Desk system and the piping and everything else, and everything is OK. No issue anywhere. I'm not sure why it's doing this, but I got the problem solved, I assume. :) Thank you for your assistance.

joshuayip
02-16-2005, 10:00 AM
No problem. =)

Joshua