Jump to content

[SOLVED] Apostrophe problem in mails


Andy17

Recommended Posts

Hey,

 

 

I have this mail script but my apostrophes are replaced with ' in the titles. I am sending HTML mails, so I believe it's a problem with the HTML encoding, but I am not sure. There is no problem in the mail text itself, just the title. Here is some of my code (the interesting part):

 

$mail = htmlspecialchars($_POST['receivermail'], ENT_QUOTES);
$mail = trim($mail);
$mail = strip_tags($mail);

$subject = htmlspecialchars($_POST['subject'], ENT_QUOTES);
$subject = trim($subject);
$subject = strip_tags($subject);

$message = htmlspecialchars($_POST['mailtext'], ENT_QUOTES);
$message = trim($message);
$message = strip_tags($message);

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "from: dizzit.net<[email protected]>";

mail($mail, $subject, $message, $headers);

 

For example, this title: "I'm testing" would appear like this in the title field: "I&#039;m testing". If you want to see for yourself, you can try it here.

 

 

Thank you for your help.

Link to comment
https://forums.phpfreaks.com/topic/134750-solved-apostrophe-problem-in-mails/
Share on other sites

You should not use the htmlspecialchars() function on the subject or To address of the mail message, since they are always treated as ASCII. Also strip_tags should be used first.

 

<?php
$mail = trim(strip_tags($_POST['receivermail']));
$subject = trim(strip_tags($_POST['subject']));
$message = trim(htmlspecialchars(strip_tags($_POST['mailtext']), ENT_QUOTES));

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: dizzit.net<[email protected]>";
?>

 

Ken

 

 

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.