Weird Characters in Mail Processing Script
Posted: Mon May 11, 2009 10:07 am
Hi all. New here, but not so new to PHP. I have encountered a problem I need urgent help with.
I have this form:
The sendflightinquiry.php is as follows:
No noticeable problem with the code, but some weird character sequence appears bringing the error:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sunrise\sendflightinquiry.php on line 24
Sorry there was an error sending your request. Please try again@e`apa-B* bh(#@`a"`(p!b(af(dR`d0
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sunrise\sendflightinquiry.php:24) in C:\xampp\htdocs\sunrise\sendflightinquiry.php on line 32
I understand why the mail function is failing. I am testing on a local server.
My problem however is with the character sequence- @e`apa-B* bh(#@`a"`(p!b(af(dR`d0 - after the message please try again. The same character sequence is introduced even when I test on a live server. i.e mail function will work fine, but redirection to appropriate page fails because of that character sequence.
Anybody who can help me understand this funny behavior?? All help appreciated.
I have this form:
Code: Select all
<form name="frmBookFlight" action="sendflightinquiry.php?flight_id=<?php echo($id);?>" method="post" enctype="multipart/form-data">
<a name="book"></a>
<table width="700" align="center" cellpadding="5" cellspacing="2">
<?php
if ($retmsg!=""){
echo ("<tr>");
echo ("<td colspan=\"2\" align=\"center\"><span style=\"color:#A40000; font-weight:bold;\">$retmsg</span></td>");
echo ("</tr>");
}
?>
<tr>
<td width="250">Your Name </td>
<td><input name="txtName" type="text" id="txtName" size="35">
<input name="txtRoute" type="hidden" id="txtRoute" value="<?php echo($route);?>"></td>
</tr>
<tr>
<td width="250">Your Email Address </td>
<td><input name="txtEmail" type="text" id="txtEmail" size="35"></td>
</tr>
<tr>
<td width="250">Departure Date (day/month/year): </td>
<td><input name="txtdepDate" type="text" id="txtdepDate" size="35"></td>
</tr>
<tr>
<td width="250">Return Date (if you need a return flight) (day/month/year):</td>
<td><input name="txtretDate" type="text" id="txtretDate" size="35"></td>
</tr>
<tr>
<td width="250">Your Phone Number</td>
<td><input name="txtTel" type="text" id="txtTel" size="35"></td>
</tr>
<tr>
<td width="250">Any Additional Request </td>
<td><textarea name="mtxDetails" cols="33" rows="6" id="mtxDetails"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" value="Submit Inquiry" name="btnSubmit" onClick="validateFlightbooking();"></td>
</tr>
</table>
</form>
The sendflightinquiry.php is as follows:
Code: Select all
<?php
$flightid=$_GET['flight_id'];
$clientname=$_POST['txtName'];
$clientemail=$_POST['txtEmail'];
$depDate=$_POST['txtdepDate'];
$retDate=$_POST['txtretDate'];
$clientphone=$_POST['txtTel'];
$reqmts=$_POST['mtxDetails'];
$flightroute=$_POST['txtRoute'];
$addressto = "ihavehiddenthis@deliberately.com";
$subject="Flight Enquiry: $flightroute";
$message="New Flight Inquiry. Details as Follows: <br/>";
$message.="Client Name: $clientname <br/>";
$message.="Email Address: $clientemail <br/>";
$message.="Flight Route: $flightroute <br/>";
$message.="Departure Date: $depDate <br/>";
$message.="Return Date: $retDate <br/>";
$message.="Client Phone No: $clientphone <br/>";
$message.="Other Details: $reqmts <br/>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$clientemail."\n";
//echo($message." ".$headers); /*For testing purposes*/
if (mail($addressto,$subject,$message,$headers)) {
$retmsg = "Thanks $clientname. Your flight enquiry has been sent successfully";
} else{
$retmsg = "Sorry. There was an error sending your inquiry. Please try again";
echo "Sorry there was an error sending your request. <a href =\"flights.php?flight_id=$flightid&retmsg=".urlencode($retmsg)."#book\"> Please try again</a>";
}
$test = 'Location: flights.php?flight_id='.$flightid&retmsg.'='.urlencode($retmsg);
echo ($test);
header('Location: flights.php?flight_id='.$flightid&retmsg.'='.urlencode($retmsg));
?>
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sunrise\sendflightinquiry.php on line 24
Sorry there was an error sending your request. Please try again@e`apa-B* bh(#@`a"`(p!b(af(dR`d0
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sunrise\sendflightinquiry.php:24) in C:\xampp\htdocs\sunrise\sendflightinquiry.php on line 32
I understand why the mail function is failing. I am testing on a local server.
My problem however is with the character sequence- @e`apa-B* bh(#@`a"`(p!b(af(dR`d0 - after the message please try again. The same character sequence is introduced even when I test on a live server. i.e mail function will work fine, but redirection to appropriate page fails because of that character sequence.
Anybody who can help me understand this funny behavior?? All help appreciated.