PHP: mail function -- how do I include an apostrophe in a parameter
I开发者_StackOverflow中文版 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.
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.
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().
精彩评论