我想将不同的邮件发送给不同的用户。但是只能发送一封邮件,然后页面显示 HTTP错误500
我可以收到一封邮件,然后在我的日志中显示
PHP致命错误:无法重新声明sendMail()(先前已声明
我尝试了 $ mail-> ClearAllRecipients(); 和 $ mail-> ClearAddresses(); ,如PHPmailer - Multiple sending of e-mail
$mail->ClearAllRecipients();
$mail->setFrom('mail@domain.com', 'Mailer');
$mail->addAddress('mail@info.com', 'Joe User');
$mail->addAddress('mail@info.com');
$mail->addReplyTo('info@example.com', 'Information');
本应作为电子邮件正文发送的数据采用会话中存储的数组格式。
[P54] => Array
(
[0] => Array
(
[id] => 54
[type] => Package
[values] => Array
(
[0] => Array
(
[name] => Farmaan Mansoori
[email] => info@demo.com
[phone] => 425698745
[date_book] => 2018-09-20
[adults] => 1
[child] => 0
[infant] => 0
[room] => 0
[suppliment] => no
[hotel] => 3 Star
[img] => London Paris.jpg
[price] => Array
(
[0] => 3540
[1] => 3100
[2] => 2635
[3] => 1
[4] => 440
)
[package_name] => london_paris
[id] => 54
[type] => Package
)
)
)
)
有人可以告诉我哪里出了问题。因此,我可以向不同的用户邮寄适合他们的不同数据。
编辑:
完整的邮件代码
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'demo@gmail.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
//Recipients
$mail->ClearAllRecipients();
$mail->setFrom('dmeo@gmail.com', 'Mailer');
$mail->addAddress('info@techyogiitsolutions.com', 'Joe User');
$mail->addAddress('demo@gmail.com');
$mail->addReplyTo('demo@example.com', 'Information');
$mail->isHTML(true);
$mail->Subject = "$pname Tour Booking Details";
$mail->Body = "Hey! $name <br> You just booked a $pname . Here are some order details. <br>Adults: $adults <br> Child: $child <br> Infant: $infant <br> Hotel Type: $hotel <br> Single Rooms: $single <br> Total: $total.";
$total = number_format($total);
$mail->AltBody = "Hey! $name You just booked a $pname . Here are some order details.Adults: $adults Child: $child Infant: $infant Hotel Type: $hotel Single Rooms: $single Total: € $total.";
$mail->send();
$mail->ClearAddresses();
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
$mail->ClearAllRecipients();
PHP致命错误:无法重新声明sendMail()(先前在 C:\ Inetpub \ vhosts \ glox \ httpdocs \ rightinteract \ global \ mailer.php:12)在 C:\ Inetpub \ vhosts \ glox.com \ httpdocs \ rightinteract \ global \ mailer.php在 第12行
答案 0 :(得分:0)
如Alex所建议。我在循环中使用 require 导致出现
问题PHP致命错误:无法重新声明sendMail()
因此我将 require 替换为 require_once ,此问题已解决。
感谢Alex的帮助:)
答案 1 :(得分:-1)