parrothead Posted August 30, 2011 Share Posted August 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/ Share on other sites More sharing options...
joel24 Posted August 30, 2011 Share Posted August 30, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/#findComment-1263397 Share on other sites More sharing options...
parrothead Posted August 30, 2011 Author Share Posted August 30, 2011 The only difference between that and my code would be the \r\n. I have tried that as well, with the same results. Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/#findComment-1263398 Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2011 Share Posted August 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/#findComment-1263399 Share on other sites More sharing options...
joel24 Posted August 30, 2011 Share Posted August 30, 2011 I realise it won't provide the same satisfaction as doing it yourself, but the phpMailer class by worxware is quite useful and can circumvent many of these email related bugs and let you focus on the application Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/#findComment-1263400 Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2011 Share Posted August 30, 2011 What does that have to do with the problem of backslashes being automagically inserted in the form data? Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/#findComment-1263401 Share on other sites More sharing options...
parrothead Posted August 30, 2011 Author Share Posted August 30, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/246005-extra-characters-in-php-email/#findComment-1263402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.