PHP邮件不从" FROM地址"

时间:2018-05-14 13:13:25

标签: php html html-email

我不知道为什么它不会从"来自"地址但来自一些人 "?@ venuse.srv.wz.cz&#34 ;. 我正在寻找任何解决方案,但我没有找到任何解决方案。它还会发送电子邮件从?@ venuse.srv.wz.cz。  我的代码:

<?php

if (isset($_POST['name']) && isset($_POST['email']))
{

$name = $_POST['name'];
$email = $_POST['email'];
$from = $_POST['email'];
$to = 'filda@seznam.cz';
$subject = 'Kontaktní formulář';
$body = '<html>
<body>
<p>Jméno: '.$name.'</p>
<p>Email: '.$email.'</p>
<p>Zpráva:<br/><br/>'.$_POST['comments'].'</p>
</body></html>';

$headers = "From: ".$email."\r\n"; 
$headers = "Reply-To: ".$email."\r\n";
$headers = "MIME-Version: 1.0" . "\r\n";

$headers ="Content-type:text/html;charset=UTF-8" . "\r\n";

$send = mail($to, $subject, $body, $headers);

} 
?>

拜托,有谁知道哪里可能有任何错误?

1 个答案:

答案 0 :(得分:1)

您正在重写标题,将它们分配给相同的变量而不进行连接。 Look at example #5

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=UTF-8\r\n';

// Additional headers
$headers .= "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";

<强> [编辑] 然后,Pawel Szalucki建议look at this post

$send = mail($to, $subject, $body, $headers, "-f $email");