skustes Posted December 17, 2009 Share Posted December 17, 2009 Hey all, New guy here....I'm having a bit of trouble with mail() that hopefully you can shed some light on. It's a basic contact form; user inputs and email is sent to someone in the directory. The email is actually sending, but the problem seems to be my headers. The From address in a received email is "unknown sender" and the HTML isn't being rendered (see below this code for an example of what I'm getting). Here is the code that's putting the whole thing together: $strMessageBody = "Name: " . $_GET['from'] . "<br/>Phone: " . $_GET['phone'] . "<br/>Email: " . $_GET['email'] . "<br/>" . $_GET['body']; $strHeaders = "MIME-Version: 1.0" . '\r\n' . "Content-type: text/html; charset=iso-8859-1" . '\r\n' . "From: " . $_GET['email'] . '\r\n'; if ($_GET['subject'] == "") { $strSubject = "Contact Form Response"; } else { $strSubject = $_GET['subject']; } if(mail(mysql_result($qryGetEmail,0,health_pro_email), $strSubject, $strMessageBody, $strHeaders)) { If you go here, you can see the output that I'm inserting into the mail() call: http://bodyfitburn.com/fitnessdirectory/functions/ajax_calls/sendcontactform.php?id=4&from=Test&[email protected]&phone=&subject=&body= It's currently set to dump the variables and die, so no mail will actually be sent. Note that the Body will look right there since the browser will render the break tags, but what I'm really getting in email is this: Name: Test<br/>Phone: <br/>Email: [email protected]<br/> So what's up with my header declarations? Any thoughts? Link to comment https://forums.phpfreaks.com/topic/185529-mail-headers-not-working-properly/ Share on other sites More sharing options...
mrMarcus Posted December 17, 2009 Share Posted December 17, 2009 new lines and returns (\r\n) needs to be enclosed in double-quotes, otherwise, they will not do their thing .. might be why your headers are not showing since they are malformed. try this: $strHeaders = "MIME-Version: 1.0\r\n"; $strHeaders .= "Content-type: text/html; charset=iso-8859-1\r\n"; $strHeaders .= "From: " . $_GET['email'] . "\r\n"; hope that helps. Link to comment https://forums.phpfreaks.com/topic/185529-mail-headers-not-working-properly/#findComment-979530 Share on other sites More sharing options...
skustes Posted December 17, 2009 Author Share Posted December 17, 2009 You're awesome! Worked like a charm...it's always something silly. Thanks so much! Scott Link to comment https://forums.phpfreaks.com/topic/185529-mail-headers-not-working-properly/#findComment-979547 Share on other sites More sharing options...
mrMarcus Posted December 18, 2009 Share Posted December 18, 2009 You're awesome! Worked like a charm...it's always something silly. Thanks so much! Scott no worries. this one's not so silly. i remember stumbling on that one before. please mark thread solved. Link to comment https://forums.phpfreaks.com/topic/185529-mail-headers-not-working-properly/#findComment-979562 Share on other sites More sharing options...
skustes Posted December 22, 2009 Author Share Posted December 22, 2009 Any chance my original post can be edited to remove the link to sendcontactform.php? It's no longer setup for debugging, so whenever someone clicks on it, it's sending emails. Link to comment https://forums.phpfreaks.com/topic/185529-mail-headers-not-working-properly/#findComment-982327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.