3 回答
TA贡献1876条经验 获得超6个赞
您应该查看$mail->addAdress,$mail->addBCC和$mail->addReplyTo字段并遵循这些字段的正确语法。
测试下面的代码。
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit']))
{
// Values need to be santiised
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$date = $_POST['date'];
$time = $_POST['time'];
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'test@handler.net';
$mail->Password = '[PASSWORD]';
$mail->setFrom('test@handler.net','Bookings'); // Emails sent via Noreply.
$mail->addAddress('bookings@salon.com',''); // Email form responses sent to bookings@salon.com
$mail->addReplyTo($email,$forename.' '.$surname); // Reply to the user who submitted the form.
$mail->addBCC('outbox@handler.net',''); // Store record of all emails sent via the system.
$mail->Subject = 'Booking Request'; // Subject of the email sent to admin@handler.net that the form responses will be contained within.
$mail->isHTML(TRUE);
$mail->Body = <<<EOD
Booking request from {$forename} with email {$email}.<br />
Contact details: <br />
Full name: {$forename} {$surname}<br />
Email: {$email} <br />
Phone number: {$phone} <br />
Service: {$service} <br />
Date: {$date} {$time}
EOD;
if(!$mail->send()) { // Send the email.
echo '';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo '';
}
}
?>
TA贡献1809条经验 获得超8个赞
这段代码是错误的,缺少一些引号
$mail->Body = '
Booking request from '.$forename.' with email '.$email;'
Test Values: $forename $surname $email $phone $service $date $time
要在字符串上启用变量替换,请使用双引号,并且您不需要使用 dot(.) 连接变量,这也可以使用像 \n 这样的转义字符,尝试像这样调整您的代码:
$mail->Body = "Booking request from $forename with email $email\n" .
"Test Values: $forename $surname $email $phone $service $date $time";
TA贡献2051条经验 获得超10个赞
首先,我们必须查看错误,因此您必须设置
$mail->SMTPDebug = 0;
进入
$mail->SMTPDebug = 3;
因此,您可以根据该错误发布该错误。
- 3 回答
- 0 关注
- 203 浏览
添加回答
举报