PHP email is sending from different address than specified

December 2, 2013 2k views
Hi Forum, My script is sending email but the email address is not the one I'm specifying on the script below. Instead a "" is the sender (which I believe is the default for my server) Any ideas? Thank you function SendMail($MailBody,$ToMail) { $IsSend='False'; try { $to = $ToMail;//""; $subject = "LockLizard PDF Viewer license Information form"; $from = ""; // Insert From Mail $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r
"; $headers .= "From:" . $from; ini_set( "sendmail_from", "" );// Insert From Mail ini_set( "SMTP", "" ); ini_set( "smtp_port", "25" ); ini_set("username",""); // Insert From Mail ini_set("password","xxxxx");// Insert From Mail Password mail($to,$subject,$MailBody,$headers); $IsSend='True'; } catch(exception $ex) { $IsSend='False'; echo 'Caught exception: ', $ex->getMessage(), "
"; } return $IsSend; }
3 Answers
Try replacing
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r

$headers .= "From:" . $from;
$headers = "Content-Type: text/html; charset=iso-8859-1\r\n"; 

$headers .= "From: {$from}";
Dear Kamal, YOU ROCK!!!

Thank you so much that did it, I have been struggling with this for so long I have no words to really thank you for this :)
Awesome! :D

Basically, you need to terminate each header with \r\n instead of \r. I've also changed a few bits of your code to make it cleaner and easier to read.
Have another answer? Share your knowledge.