chiefrokka Posted May 29, 2008 Share Posted May 29, 2008 I've been searching for an hour on these forums and trying all sorts of code people have posted for the Mail Headers syntax, but I keep getting the email and it returns the server host for "From: [email protected]" can someone please post code that works with a variable for From: my latest attempt is: <?php $to = $Email; $headers = 'FROM: $Admin_Email'; $headers .= 'Reply-To: $Admin_Email'; $subject = 'work you piece of crap'; $headers = 'MIME-Version: 1.0' . '\r\n'; $headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n'; ?> Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/ Share on other sites More sharing options...
trq Posted May 29, 2008 Share Posted May 29, 2008 Variables are not interpolated when within signle quoted strings, change them to double. Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552299 Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 Also, FROM: should be From: Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552315 Share on other sites More sharing options...
chiefrokka Posted May 29, 2008 Author Share Posted May 29, 2008 hmm, still sending the servers address. I changed code to this. the message has some html that I took out because I use variables within the tables. <?php $to = $Email; $headers = "From: $Admin_Email"; $headers .= "Reply-To: $Admin_Email"; $subject = "Survivor League - $user's Week $Current_Week Pick!"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; $message = ' <html> <head> </head> <body> </body> </html> '; ?> Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552463 Share on other sites More sharing options...
chiefrokka Posted May 29, 2008 Author Share Posted May 29, 2008 ok I figured it out finally. I took out these lines below and it works fine now. $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; so now all I have is: <?php $to = $Email; $headers = "From: $Admin_Email"; $headers .= "Reply-To: $Admin_Email"; ?> Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552469 Share on other sites More sharing options...
chiefrokka Posted May 29, 2008 Author Share Posted May 29, 2008 ok I just realized that the From: $Admin_Email works but the HTML portion of the email doesn't show up properly without $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; so close but yet so far away. but when I put those 2 in the headers, the email doesn't use the $Admin_Email but sends the servers address. Is there a way to send HTML as well as using a variable for From: Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552582 Share on other sites More sharing options...
PFMaBiSmAd Posted May 29, 2008 Share Posted May 29, 2008 Each line of the header need a \r\n Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552597 Share on other sites More sharing options...
chiefrokka Posted May 29, 2008 Author Share Posted May 29, 2008 <?php $to = $Admin_Email; $headers = "From: $Admin_Email \r\n"; $headers .= "Reply-To: $Admin_Email \r\n"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; ?> the above code didn't work. I have double quotes for part of the headers with variables then the last 2 are single quotes. do I have wrong syntax in the first 2 with? Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552600 Share on other sites More sharing options...
fook3d Posted May 29, 2008 Share Posted May 29, 2008 <?php $to = $Admin_Email; $headers = "From: $Admin_Email \r\n"; $headers .= "Reply-To: $Admin_Email \r\n"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; ?> the above code didn't work. I have double quotes for part of the headers with variables then the last 2 are single quotes. do I have wrong syntax in the first 2 with? You are resetting the $headers value before you are not using the .= operator. Using the code below will show all the $header lines. <?php $to = $Admin_Email; $headers = "From: $Admin_Email \r\n"; $headers .= "Reply-To: $Admin_Email \r\n"; // To send HTML mail, the Content-type header must be set $headers .= "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; ?> To see what value it is returning, use echo $headers; below all the $headers variables. If this isn't what your asking, look past it, I'm a dumbass at times and don't fully understand your issue Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552610 Share on other sites More sharing options...
chiefrokka Posted May 29, 2008 Author Share Posted May 29, 2008 ahh, that's what it was. I forgot the period before the = on the 'MIME-Version' line. you are the man. thank you Link to comment https://forums.phpfreaks.com/topic/107735-mail-header-from-keeps-returning-server-address-not-variable/#findComment-552620 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.