当用户在我的网站上的表单上输入他们的电子邮件时,我会收到一封包含他们信息的电子邮件。我希望能够回复该电子邮件并将其电子邮件自动填写为“收件人:”但我遇到了麻烦。我发现了这个问题并尝试了解决方案:reply-to address in php contact form但它不适用于我,我不知道为什么。
这是我的PHP:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$to = 'amanda@myemail.com';
$headers = "BCC: clients@myemail.com\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$subject = '*** Quote Request';
$name = $_POST['name'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$passengers = $_POST['passengers'];
$service = $_POST['service'];
$email = $_POST['email'];
$message = <<<EMAIL
Quote submission from: $name
Name: $name
Phone Number: $phone
Date: $date
Time: $time
Pickup Location: $pickup
Drop Off Location: $dropoff
Total Passengers: $passengers
Service needed: $service
Email: $email
EMAIL;
if($_POST) {
mail($to, $subject, $message, $headers);
}
header('Location: thankyou.html');
exit();
?>
这是我得到的错误信息,总结起来:
未定义的变量:第9行的/contact-form-handler.php中的电子邮件警告:无法修改标题信息 - 已经发送的标题(以/ contact-form-handler.php:9开头的输出)/ contact-form第44行的-handler.php
问题是变量$email
,因为如果我放了一个回复并指定一封电子邮件,它就可以了。我想也许是因为变量是在我在标题中调用后定义的,但是将它添加到底部不起作用。我是PHP的新手,所以我不确定为什么这个变量不起作用。
我也尝试过:
$headers = "BCC: clients@myemail.com\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
任何帮助将不胜感激!
答案 0 :(得分:1)
在定义变量之前使用变量!
将此块移动到脚本的顶部:
$name = $_POST['name'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$passengers = $_POST['passengers'];
$service = $_POST['service'];
$email = $_POST['email'];
就像那样:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$name = $_POST['name'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$passengers = $_POST['passengers'];
$service = $_POST['service'];
$email = $_POST['email'];
$to = 'amanda@myemail.com';
$headers = "BCC: clients@myemail.com\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$subject = '*** Quote Request';
$message = <<<EMAIL
Quote submission from: $name
Name: $name
Phone Number: $phone
Date: $date
Time: $time
Pickup Location: $pickup
Drop Off Location: $dropoff
Total Passengers: $passengers
Service needed: $service
Email: $email
EMAIL;
if($_POST) {
mail($to, $subject, $message, $headers);
}
header('Location: thankyou.html');
exit();
?>
答案 1 :(得分:0)
好像您没有收到联系表单中的$i
(重新:“未定义的变量:电子邮件”)
检查邮件输入字段的名称......