简体   繁体   English

php邮件发件人:&回复至:标头问题

[英]php mail From: & Reply-to: headers issue

Ok so I am writing a php contact form that will send two emails. 好的,所以我正在写一个php联系人表格,该表格将发送两封电子邮件。 One to the webmaster with the info and a similar confirmation email sent to the form submitter. 向网站管理员发送信息,并向表单提交者发送类似的确认电子邮件。

The problem is with the confirmation email. 问题出在确认电子邮件上。 I am trying to configure the From: header and the Reply-to: but and for some reason catching a hurdle. 我正在尝试配置From:标头和Reply-to:但由于某种原因遇到了障碍。

Originally I had my php set up as so declaring each header parameter... 最初我将php设置为声明每个标头参数...

$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')

This as I understand is the proper way, but I am still having the From: say "mydomain.com@myhostdomain.com as both the senders name and senders email. Which is how it was before I even declared the headers and it was null. 据我了解,这是正确的方法,但是我仍然使用发件人:说“ mydomain.com@myhostdomain.com作为发件人名称和发件人电子邮件。这是我什至在声明标头之前的样子,它为空。

So then I tried an override using 所以我尝试使用

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

Which returned the same results. 其中返回相同的结果。

So I have resorted to simply using the following, w/o declared headers. 因此,我仅使用了以下无声明的标头。

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

This give me the proper from/reply-to address, but also puts it as the senders name. 这为我提供了正确的“发自/回复至”地址,但也将其作为发件人姓名。

So my question is if there is any way to write the headers so the email formulates as such: 所以我的问题是,是否有任何方式可以编写标题,以便电子邮件的格式如下:

Senders Name: myDomain.com 发件人姓名:myDomain.com

Senders Email: info@mydomain.com 发件人电子邮件:info@mydomain.com

I use an array for my headers, then implode them on "\\r\\n": 我为标题使用数组,然后将其内嵌到“ \\ 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM