I am having trouble with a valid email address with an apostrophe as the $to
parameter. I don't know how to pass a parameter with an apostrophe to the PHP mail()
function.
Asked
Active
Viewed 2,581 times
1
-
thanks, tony, I tried your suggestion and that email address isn't getting thru the mail function. I'm sending three email addresses, one at a time. The two normal addresses get thru OK but the one with the apostrophe doesn't make it? ideas? – BPetrarca Sep 20 '11 at 00:08
2 Answers
0
Wrap the email address in double quotes. But are you sure about the apostrophe being valid?
Edit, yup, it's legal. Just wrap it in double quotes, but also add backslashes in front of double quotes, spaces, and backslash.

Ariel
- 25,995
- 5
- 59
- 69
-
Ariel, I think you've got it. I haven't been able to upload the fix to my server--very slow. I will let you know ASAP. Thanks! – BPetrarca Sep 20 '11 at 00:34
-
Ariel, I just was able to try the double quotes in the PHP mail parameter and it doesn't get thru mail. I'm wondering if the mail function is not capable of taking an email with quotes in it? – BPetrarca Sep 20 '11 at 12:54
-
Ariel. I got your suggestion to work by putting the double quotes right in the mail paramter. Thanks loads. – BPetrarca Sep 20 '11 at 13:45
0
I would really doubt an apostrophe is valid in an E-Mail address (even through the spec allows it) but to pass a parameter you could do one of the following:
$to = "this is a string with an ' in it";
or
$to = 'this is a string with an \' in it';
Now you can use it for mail();
mail($to, $subject, $message, $headers);
Either way you'll be sending the apostrophe to mail().

Jason
- 15,017
- 23
- 85
- 116