Jump to content

Sending mail with html headers issues


TGWSE_GY

Recommended Posts

OK so I am trying to send a email with the results of a submitted form to a specified email address. However when the email is received the data is not displayed rather the variable names are. See code and resulting email address below.

 

// custom route code
//Send Email	
// recipients
$to  = '********@*********.com';

// subject
$subject = 'Jobs Form Submission!';

// message
$message = '
<html>
<head>
  <title>Jobs Form Submission!</title>
</head>
<body>
	Title: $job_title<br /> 
	Company: $job_company<br />
	Introduction: $job_intro <br />
	Description: $job_description <br /> 
	Required Qualifications: $job_req_qualifi <br />
	Preferred Qualifications: $job_preerred_qualifi <br />
	Contact Name: $job_contact_name <br />
	Contact Company: $job_contact_company <br />
	Contact E-mail: $job_contact_email <br /> 
	Contact Phone: $job_contact_phone <br /> 
	Contact Fax: $job_contact_fax <br />
</body>
</html>
';

// 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";

// Additional headers
$headers .= 'To: ******** <********@*********.com>' . "\r\n";
$headers .= 'From: $job_contact_email <$job_contact_email>' . "\r\n";
$headers .= 'Cc:' . "\r\n";
$headers .= 'Bcc:' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

 

Email Address:

MIME-Version: 1.0

Content-type: text/html; charset=iso-8859-1

To: ********<******@**********.com>

From: $job_contact_email <$job_contact_email@***********.com>

Cc:

 

 

<html>

<head>

  <title>Jobs Form Submission!</title>

</head>

<body>

Title: $job_title<br />

Company: $job_company<br />

Introduction: $job_intro <br />

Description: $job_description <br />

Required Qualifications: $job_req_qualifi <br />

Preferred Qualifications: $job_preerred_qualifi <br />

Contact Name: $job_contact_name <br />

Contact Company: $job_contact_company <br />

Contact E-mail: $job_contact_email <br />

Contact Phone: $job_contact_phone <br />

Contact Fax: $job_contact_fax <br />

</body>

</html>

 

 

Any pointers would be great. Thanks in advance 0_o

Link to comment
https://forums.phpfreaks.com/topic/212057-sending-mail-with-html-headers-issues/
Share on other sites

Anything inside of a single-quoted string is interpreted as a literal value. You'd need to use double quotes around the strings, or proper string concatenation to get it to work as intended.

Ok so I found the solution or at least the solution that worked for me other than I receive 2 emails from one submission of the form. However the header issue was in fact because I was trying to send html and some applications remove the custom headers by default ie. MS Outlook, and many others. So I corrected this issue by removing all html code from the message and used

\n

for a carriage return. Below is the code I am using now. Once I find a fix for the duplicate emails I will post that solution as well.

 

Thanks again for your time and help.

 

// recipients
$to  = "******@********.com";

// subject
$subject = "Jobs Form Submission!";

// message
$message ="
	Title: " . $job_title . "\n 
	Company: " . $job_company . "\n
	Introduction: " . $job_intro . "\n
	Description: " . $job_description . "\n 
	Required Qualifications: " . $job_req_qualifi . "\n
	Preferred Qualifications: " . $job_preerred_qualifi . "\n
	Contact Name: " . $job_contact_name . "\n
	Contact Company: " . $job_contact_company . "\n
	Contact E-mail: " . $job_contact_email . "\n 
	Contact Phone: " . $job_contact_phone . "\n 
	Contact Fax: " . $job_contact_fax . "\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";

// Additional headers
$headers .= "From: " . $job_contact_email ."\r\n";
$headers .= "Reply-To: " . $job_contact_email . "                                                                                                                                                                                                                                                                                                                                \r\n";
// Mail it
mail($to, $subject, $message, $headers);

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.