php 邮件发件人:&Reply-to:headers 问题

php mail From: & Reply-to: headers issue

好的,我正在写一个 php 联系表格,它将发送两封电子邮件。一封给网站管理员,其中包含发送给表单提交者的信息和类似的确认电子邮件。

问题出在确认邮件上。我正在尝试配置 From: header 和 Reply-to: 但由于某种原因遇到了障碍。

最初我将 php 设置为声明每个 header 参数...

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$guests = $_POST['guests'];
$type = $_POST['type'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$message = $_POST['message'];
$formcontent="THIS IS A FORM SUBMISSION FROM domain.COM... \n \n PARTY INQUIRY \n \n From: $name \n Email: $email \n Phone: $phone \n # of Guests: $guests \n Type: $type \n Date Requested: $month $day, $year \n \n Additional Info: $message";
$comfirmcontent="THIS IS A CONFIRMATION OF YOUR FORM SUBMISSION TO domain.COM... \n \n PARTY INQUIRY \n \n From: $name \n Email: $email \n Phone: $phone \n # of Guests: $guests \n Type: $type \n Date Requested: $month $day, $year \n \n Additional Info: $message \n\n\n If you have any further questions please email info@mydomain.com";
$confirmsubject="Confirmation for your inquiry to mydomain.COM";
$confirmheader="From: mydomain.com" . "\r\n" .
"Reply-To: info@mydomain.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$recipient = "info@domain.com";
$subject = "Party Inquiry from Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, $confirmsubject, $comfirmcontent, $confirmheader) or die("Error!");
header('Location: party-form-thank-you.html')

据我所知,这是正确的方法,但我仍然有发件人:说“mydomain.com@myhostdomain.com 作为发件人姓名和发件人电子邮件。这是以前的样子我什至声明了 headers 并且它是空的。

然后我尝试使用

进行覆盖
mail($email, $confirmsubject, $comfirmcontent, $confirmheader,'-finfo@mydomain.com') or die("Error!");

返回相同的结果。

所以我只使用了以下内容,w/o 声明了 headers。

mail($email, $confirmsubject, $comfirmcontent, null,'-finfo@mydomain.com') or die("Error!");

这给了我正确的 from/reply-to 地址,但也把它作为发件人姓名。

所以我的问题是,是否有任何方法可以编写 header,以便电子邮件这样表述:

发件人姓名:myDomain.com

发件人邮箱:info@mydomain.com

我为我的 headers 使用数组,然后 implode 它们在“\r\n”:

$headers = array();
$headers[] = 'Content-type: text/html; charset="UTF-8";';
$headers[] = 'Date: ' . date('r', $_SERVER['REQUEST_TIME']);
$headers[] = 'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . (empty($_SERVER['SERVER_NAME']) ? '' : '@' . $_SERVER['SERVER_NAME']) . '>';

// here is the from and reply-to part:
$headers[] = 'From: "' . $fromName . '" <' . $fromAddress . '>';
$headers[] = 'Reply-To: "' . $replyToName . '" <' . $replyToAddress . '>';
$headers[] = 'X-Mailer: PHP v' . phpversion();
if (!empty($_SERVER['SERVER_ADDR'])) {
    $headers[] = 'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'];
}

// Use the implode function to collapse the array into a single string
mail($to, $subject, $message, implode("\r\n", $headers));