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
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
  • 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:
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

724 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