有与此类似的问题,但它们未概述我的案情Similar Question (Link)
<form method="post" name="process.php" action="process.php">
Name: <input type="text" name="name">
Email Address: <input type="text" name="email">
Message: <textarea name="message"></textarea>
<input type="submit" value="Send Form">
</form>
此文件另存为index.php
在我的bookings
文件夹中。
我已经创建了这段代码来处理表单提交,这确实有效。
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = $visitor_email;
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "bookings@mycompany.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "user@emailprovider.com";
$headers = "From: 'bookings@mycompany.com' \r\n";
$headers .= "Reply-To: 'bookings@mycompany.com' \r\n";
mail($to,$email_subject,$email_body,$headers);
$email_body = "Hi, we have received your booking request, someone from the team will get back to you shortly"
?>
<p>Sending Booking Request....</p>
我认为这与重叠变量有关,但是我希望能够向用户发送电子邮件确认已收到他们的请求。目前,用户确实收到了电子邮件,但其内容与发送给bookings@mycompany.com
预先感谢:)
答案 0 :(得分:1)
要先发送电子邮件,然后再更改电子邮件正文。更改为:
<?php
$to = "user@emailprovider.com";
$headers = "From: 'bookings@mycompany.com' \r\n";
$headers .= "Reply-To: 'bookings@mycompany.com' \r\n";
$email_body = "Hi, we have received your booking request, someone from the team will get back to you shortly";
mail($to,$email_subject,$email_body,$headers);
?>
答案 1 :(得分:0)
问题:$email_body
在邮件发送后分配。
替换
mail($to,$email_subject,$email_body,$headers);
$email_body = "Hi, we have received your booking request, someone from the team will get back to you shortly"
与
$email_body = "Hi, we have received your booking request, someone from the team will get back to you shortly"
mail($to,$email_subject,$email_body,$headers);