dk4210 Posted August 12, 2011 Share Posted August 12, 2011 Hello Guys, I have a strange issue that I am trying to figure out... I have a php mail script that I can't get the correct from email address to display in the email client Here is my code notice the $from2 var If I have this code - $headers = "From:'.$from2.'\r\n"; I get a default email address If I add this code - $headers = "From:[email protected]\r\n"; it works fine. // multiple recipients $to = $email; $from2 = $_SESSION['no_reply']; //echo "This is the from2" . $from2; //exit; // subject $subject2 = 'You have a new message from ' . $_SESSION['site_name'] .''; //begin of HTML message $message2 = 'You have a new message.<br>'; $message2 .= 'From: '. $username1; $message2 .= '<br>Message Details'; $message2 .= '<br><a href="'.$site_url .'">Log in to see the message</a>'; $message2 .= '<br><br><br>'; //end of message $headers = "From:'.$from2.'\r\n"; $headers .= "Content-type: text/html\r\n"; // Mail it mail($to, $subject2, $message2, $headers); I did echo out the $form2 to make sure it had a value and it does.. Please advise.. Thanks, Dan Link to comment https://forums.phpfreaks.com/topic/244599-php-mail-headers-reply-from-address-with-var/ Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 $headers = "From:".$from2."\r\n"; Link to comment https://forums.phpfreaks.com/topic/244599-php-mail-headers-reply-from-address-with-var/#findComment-1256340 Share on other sites More sharing options...
chintansshah Posted August 12, 2011 Share Posted August 12, 2011 You can do this using mail($to, $subject2, $message2, "From: ".$form2); Link to comment https://forums.phpfreaks.com/topic/244599-php-mail-headers-reply-from-address-with-var/#findComment-1256357 Share on other sites More sharing options...
dk4210 Posted August 12, 2011 Author Share Posted August 12, 2011 Hi WebStyles, I tried the following / multiple recipients $to = $email; //$from2 = "someonelse@".$url.""; $from2 = $_SESSION['no_reply']; //echo "This is the from2" . $from2; //exit; // subject $subject2 = 'You have a new message from ' . $_SESSION['site_name'] .''; //begin of HTML message $message2 = 'You have a new message.<br>'; $message2 .= 'From: '. $username1; $message2 .= '<br>Message Details'; $message2 .= '<br><a href="'.$site_url .'">Log in to see the message</a>'; $message2 .= '<br><br><br>'; //end of message $headers = "From:".$from2."\r\n"; $headers .= "Content-type: text/html\r\n"; // Mail it mail($to, $subject2, $message2, $headers); And it never sent the email at all chintansshah, I tried what told me to do and it just sent the default email address.. The strange thing is if I manually add the address in there it works fine but if I try to use a variable it malfunctions in one way or another.. Please advise Link to comment https://forums.phpfreaks.com/topic/244599-php-mail-headers-reply-from-address-with-var/#findComment-1256366 Share on other sites More sharing options...
dk4210 Posted August 12, 2011 Author Share Posted August 12, 2011 Even though the var has correct value Link to comment https://forums.phpfreaks.com/topic/244599-php-mail-headers-reply-from-address-with-var/#findComment-1256367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.