Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

php Mail

Posted on 2006-10-31
Last Modified: 2010-04-06
I'm using the php mail function to send structured emails based on data entered on web forms.

Some of the data entered MAY have single quote or double quote characters in the text. We want the email to reflect EXACTLY what's entered.

It appears that the php mail function "escapes" special characters. So, for example, if the input was O'Hanlon, the email message contains
Customer Name: O\'Hanlon

Is there a way to disable php mail from "escaping" these characters?

If not, is there anither "open source" mail package that doesn't do this?

Question by:Richard Korts
  • 4
  • 3
LVL 29

Expert Comment

ID: 17845688
Are you sure magic quotes is not on?
Try this line before you send the mail:

Author Comment

by:Richard Korts
ID: 17845885
To TeRRef,

I never heard of set_magic_quotes, but I looked it up.

I tried it but it didn't work. However, I forgot to mention that the actual character at that time is the ` not the ', because I changed all the ' to ` to avoid SQL database insert problems.

Does set_magic_quotes deal with ` also or do I have to send the email AND THEN change ' to `?

LVL 29

Accepted Solution

TeRReF earned 500 total points
ID: 17845988
I don't understand why you're affraid of INSERT problems while sending mail? If you mean that you changed the chars before you put the names in the DB, there are better ways of doing that. THere is a neat function called mysql_real_escape_string() that handles these potential problems for you:

I don't think set_magic_quotes deals with the ` char.

ANyway, I'm not sure why the mail function escapes on it's own. Can't recall ever having these problems. But then again, I usually use PHPMailer for these tasks since it's much better equiped. Maybe you can give that a try:
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

by:Richard Korts
ID: 17846035
To TeRRef,

I'm not afraid of INSERT problems while sending mail. It's just that the sequence of my logic in the php program converted all the ' to ` BEFORE I sent the email because the sending of the mail was an added on requirement.

I know about mysql_real_escape_string() but it doesn't solve the problem on the other end.

Anyway, I'll try set_magic_quotes BEFORE the quote change & if that doesn't work, I'll try PHPmailer.

Thanks for your quick responses, as usual.

Author Comment

by:Richard Korts
ID: 17846135
To TeRRef,

I did set_magic_quotes_runtime(0) while the email body had data with ' in it. Still doesn't work.

I'll look at PHPmailer.


Author Comment

by:Richard Korts
ID: 17846400
To TeRRef,

I tried this & it worked. It removed the "\" from the email body.

$body = stripslashes($body);
$mres = mail($mailto, $subj, $body, $header);

So your answer wasn't the full solution but I'm giving you the points because you are very knowledgable of php, you've helped me before & your comments led me to the solution.

LVL 29

Expert Comment

ID: 17846599
Well done! Thanks for the points :)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
create wsdl for check policy price 32 35
Problem with Connection / Parameter: 4 21
WordPress/WooCommerce security best practices? 2 105
cookies analysis tools 2 100
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question