Solved

php Mail

Posted on 2006-10-31
7
178 Views
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?

0
Comment
Question by:Richard Korts
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 17845688
Are you sure magic quotes is not on?
Try this line before you send the mail:
set_magic_quotes_runtime(0);
0
 

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 `?

Thanks
0
 
LVL 29

Accepted Solution

by:
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:
http://php.net/mysql_real_escape_string

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:
http://sourceforge.net/projects/phpmailer/
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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.
0
 

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.

Thanks
0
 

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.

Cheers!      
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17846599
Well done! Thanks for the points :)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now