views:

1114

answers:

5

When I try to send a HTML encoded email from PHP, if the subject line contains special chars like "Here's the information you requested", PHP encodes it to read "Here's the information you requested."

How do I fix this?

A: 

Try using SwiftMailer or other library that handles all the complexities of creating and encoding HTML mail for you.

tpk
I'm doing this inside SugarCrm and we're trying to use SugarCRM's SugarPHPMailer class to send these. Boss wants to use SugarCRM's functions.
ericwindham
A: 

Try running the subject line through html_entity_decode(), looks like maybe you have some entities in the subject line.

Paul Dixon
Already tried this. Thanks, though.
ericwindham
+1  A: 

If the string really doesn't contain encoded values before you send, take a look at this:

$subject= mb_encode_mimeheader($subject,"UTF-8", "B", "\n");
// or
$subject= mb_encode_mimeheader($subject,"UTF-7", "Q", "\n");


Take a look at these posts related to SugarCRM:

Michael Haren
Tried both to no avail. I've never seen this before. Thanks for your reply.
ericwindham
Add more references
Michael Haren
A: 

Submitting the offending block of code often times will ensure you a better response faster. You are likely encoding the text somewhere before this action takes place. As previously suggested you can seek out that action, and correct it, or you can simply decode the subject line before sending the email.

Jonathan Sampson
I've tried decoding it before sending it. I've also tried sending the same email from the php mail() function rather than the SugarPHPMailer class. It isn't SugarCrm specific. Same thing happens with mail().
ericwindham
You need to post code then it would seem.
Jonathan Sampson
A: 

Here's what the code looks like using PHP mail():

$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: ' . $mod_params['name'] . '<' . $mod_params['email'] . '>' . "\r\n";

$headers .= 'From: [email protected]' . "\r\n";

$email_to = $mod_params['email'];

$email_sub = "Here's the Information You Requested";

$body = html_entity_decode("" . $email_html_body . "");

mail($email_to,$email_sub,$body,$headers);

It gives the same error as running it through the SugarPHPMailer class.

ericwindham