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?
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?
Try using SwiftMailer or other library that handles all the complexities of creating and encoding HTML mail for you.
Try running the subject line through html_entity_decode(), looks like maybe you have some entities in the subject line.
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:
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.
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.