3 回答

TA貢獻1876條經(jīng)驗 獲得超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條經(jīng)驗 獲得超8個贊
這段代碼是錯誤的,缺少一些引號
$mail->Body = '
Booking request from '.$forename.' with email '.$email;'
Test Values: $forename $surname $email $phone $service $date $time
要在字符串上啟用變量替換,請使用雙引號,并且您不需要使用 dot(.) 連接變量,這也可以使用像 \n 這樣的轉義字符,嘗試像這樣調(diào)整您的代碼:
$mail->Body = "Booking request from $forename with email $email\n" .
"Test Values: $forename $surname $email $phone $service $date $time";

TA貢獻2051條經(jīng)驗 獲得超10個贊
首先,我們必須查看錯誤,因此您必須設置
$mail->SMTPDebug = 0;
進入
$mail->SMTPDebug = 3;
因此,您可以根據(jù)該錯誤發(fā)布該錯誤。
- 3 回答
- 0 關注
- 231 瀏覽
添加回答
舉報