Jump to content

Extra Characters in PHP Email


parrothead

Recommended Posts

I have an email form that I use to generate email messages to a club distribution list. I add the body of the message from a form that sends that message to a php script. The emails are a mix of html directly from the script as well as what is sent to the script from the web page form.

 

Example:

$mailmessage = '<html><body>header of message' . $MessageFromForm . 'footer of message </body></html>';

 

**where $MessageFromForm is requested from the form and is the body of the email message.

 

The html header and footer of the message look fine, but the code that came from my html form does not work properly. That code replaces a ' with \', and the html tags do not work. I do have the following included in my headers:

 

$headers = "MIME-Version: 1.0" . "\n";

$headers .= "Content-type:text/html;charset=iso-8859-1" . "\n";

 

Any ideas on what could cause this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/
Share on other sites

from php.net

$to = '[email protected], [email protected]';

// 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: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

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

If you're getting data from a form that has backslashes escaping the quotes, you probably have magic_quotes_gpc() set to ON in your php.ini file. If phpinfo() shows it to be On, and you are able to do so, set it to Off.

If you're getting data from a form that has backslashes escaping the quotes, you probably have magic_quotes_gpc() set to ON in your php.ini file. If phpinfo() shows it to be On, and you are able to do so, set it to Off.

 

THANK YOU! I spent hours trying to figure out what was causing this. It was magic quotes. I used stripslashes on my variable to fix the issue. I think this must have happened when the PHP version switched as this problem did not exist before. I really appreciate the help!

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.