发送电子邮件标头

时间:2014-05-23 14:34:04

标签: php wordpress email

我有发送电子邮件的代码:

$email = $_POST['message_email'];
$headers = 'From: '. $email . "\r\n" .
    'Reply-To: ' . $email . "\r\n";

之前我检查电子邮件是否正确所以必须如此。 然后我发了一封电子邮件:

$sent = wp_mail($newTo, $subject, $companyName . "\n" . $email . "\n" . $phoneNumber . "\n" . strip_tags($message) . "\n" . $outputMail, $headers);

并且它不起作用。我已尝试将标题更改为:

$headers = 'From: My Name <myname@mydomain.com>' . "\r\n\\";

然后它的工作原理。为什么我的代码无效?我需要提供从表单中恢复的电子邮件。

1 个答案:

答案 0 :(得分:0)

试试这样:

****我编辑了代码****

$from = "your@mail.com";
    $to = "to@mail.com";
    $message = "Message";
    $subject = 'subject';
    $headers  = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
    $headers .= "From: ".$from."\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    if(mail($from, $subject, $message, $headers)){
        //success
    }else{
        //error
    }