dongyi8383 2015-07-20 01:53
浏览 53
已采纳

设置PHP标头后,我收到meme类型作为from值?

This should be pretty straightforward. I'm sending an email using an Angular JS's HTTP object ajax request.

The ajax request works fine, my data is passed to the PHP in JSON format (The Angular JS default).

The email sends correctly, I'm just having issues with my header formatting. I have the following PHP code...

$postdata = file_get_contents("php://input");
    $request = json_decode($postdata);

    $user_email = $request->email;
    $user_subject = $request->subject;
    $user_message_input = $request->message;

    $user_headers = 'From: ' . '<noReply@AllenHundley.com>' . '
';
    $user_headers .= "MIME-Version: 1.0
";
    $user_headers .= "Content-Type: text/html; charset=ISO-8859-1
";

    $user_message = "
        <html>
            <head>
                <title>
                    Thanks for contacting me!
                </title>
            </head>
            <body>
                " . $user_message_input . "
            </body>
        </html>
    ";

    mail($user_email, $user_subject, $user_message, $user_headers);

As I mentioned before, the email sends as an HTML email. The only problem is that in my email I receive this as the from field:

rnMIME-Version: 1.0 noReply@allenhundley.com

Why are the separations being viewed as escaped strings rather than separators?

  • 写回答

1条回答 默认 最新

  • drno94939847 2015-07-20 01:59
    关注

    needs to be wrapped in double quotes, i.e. " "

    In PHP, single quotes are for literal texts. You can read more information here: http://php.net/manual/en/language.types.string.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?