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<no-reply@dizzit.net>";

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
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<no-reply@dizzit.net>";
?>

 

Ken

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.