Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mail()发送2封电子邮件_Php_Email - Fatal编程技术网

Php 使用mail()发送2封电子邮件

Php 使用mail()发送2封电子邮件,php,email,Php,Email,我正试图向不同的地址和主题发送两封电子邮件 $to = 'contact@example.com'; $from = $_POST['email']; $subject = 'Contact - '.$_POST['subject']; $message = utf8_decode($_POST['msg'])."\r\n"; $message .= "\r\n-------"; $message .= "\r

我正试图向不同的地址和主题发送两封电子邮件

$to = 'contact@example.com';
        $from    = $_POST['email'];
        $subject = 'Contact - '.$_POST['subject'];
        $message = utf8_decode($_POST['msg'])."\r\n";
        $message .= "\r\n-------";
        $message .= "\r\nPhone: ".$_POST['tel']." - E-mail: ".$_POST['email'];
        $headers = 'From:'.$_POST['email']. "\r\n" .
        'Reply-To:'.$_POST['email']. "\r\n" .
        'X-Mailer: PHP/' . phpversion();



        $headers2 = "From: Company <noreply@example.com>\n";
        $headers2 .= "MIME-Version: 1.0\r\n";
        $headers2 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

        $message2 = "<html><body>
        Thanks for your contact!</body></html>
        ";
mail($to, $subject, $message, $headers); 
mail($from, "Thanks for your contact!", $message2, $headers2);
但只有最后一个起作用了。发生了什么?谢谢

$headers2 = "From: Company <example@example.com>\r\n";

在末尾添加“\r”。但这是第二封电子邮件。

我的第一个猜测是您正在向noreply@example.com这肯定行不通。除非我弄错了,否则如果$to是一个有效的电子邮件地址,它应该可以工作

编辑 好的,那么看看这个,不是第一个问题的直接答案。但我会考虑使用这样的东西:


除非您有充分的理由重新实现邮件模块,否则如果有人已经做得很好,我会尽量不重新实现它。邮件rfc可能有些复杂,因为它依赖于太多rfc。。。也就是说,使用一个经过验证的解决方案可能比尝试推出自己的解决方案解决更多的问题

将$to设置为转到2个电子邮件地址

$to = 'noreply@example.com,'.$from;

CrystalBall.exe已停止工作。你检查过错误或日志消息吗?顺便问一下,什么是CrystalBall.exe?这是一个例子。我改变了我的问题以获得更多的理解。