Jump to content

Mail Headers Not Working Properly


skustes

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.