我有一个基本的smtp邮件脚本,效果很好,但我唯一需要的是自定义邮件体。我试图在脚本中定义和插入值,但在某处代码给了我错误。我在哪里做错了?
<?
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "mail.host.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "info@host.com"; // SMTP username
$mail->Password = "123456"; // SMTP password
$mail->From = "info@host.com";
$mail->Fromname = "John Doe";
$mail->AddAddress("info@gmail.com","John Doe");
$mail->Subject = $_POST['content'];
$mail->Body = (".$arrival_date.", ".$arrival_pickup_location.", ".$arrival_dropoff_location.", ".$arrival_flight_number.", ".$arrival_fligth_time.", ".$arrival_dropoff_adress.", ".$phone_number.", ".$reservation_name.", ".$email_adress.", ".$country.", ".$additional_requests.");
$arrival_date = $_POST['arrival_date'];
$arrival_pickup_location = $_POST['arrival_pickup_location'];
$arrival_dropoff_location = $_POST['arrival_dropoff_location'];
$arrival_flight_number = $_POST['arrival_flight_number'];
$arrival_fligth_time = $_POST['arrival_fligth_time'];
$arrival_dropoff_adress = $_POST['arrival_dropoff_adress'];
$reservation_name = $_POST['reservation_name'];
$phone_number = $_POST['phone_number'];
$email_adress = $_POST['email_adress'];
$passenger = $_POST['passenger'];
$country = $_POST['country'];
$additional_requests = $_POST['additional_requests'];
if(!$mail->Send())
{
echo "Mesagge not delivered <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message sent";
?>
答案 0 :(得分:1)
在您尝试使用$mail->Body
对象设置<?php
$arrival_date = $_POST['arrival_date'];
$arrival_pickup_location = $_POST['arrival_pickup_location'];
$arrival_dropoff_location = $_POST['arrival_dropoff_location'];
$arrival_flight_number = $_POST['arrival_flight_number'];
$arrival_fligth_time = $_POST['arrival_fligth_time'];
$arrival_dropoff_adress = $_POST['arrival_dropoff_adress'];
$reservation_name = $_POST['reservation_name'];
$phone_number = $_POST['phone_number'];
$email_adress = $_POST['email_adress'];
$passenger = $_POST['passenger'];
$country = $_POST['country'];
$additional_requests = $_POST['additional_requests'];
$message = '<ul><li>' . $arrival_date . "</li>";
$message .= '<li>' . $arrival_pickup_location . "</li>";
$message .= '<li>' . $arrival_dropoff_location . "</li>";
$message .= '<li>' . $arrival_flight_number . "</li>";
$message .= '<li>' . $arrival_fligth_time . "</li>";
$message .= '<li>' . $arrival_dropoff_adress . "</li>";
$message .= '<li>' . $phone_number . "</li>";
$message .= '<li>' . $reservation_name . "</li>";
$message .= '<li>' . $email_adress . "</li>";
$message .= '<li>' . $country . "</li>";
$message .= '<li>' . $additional_requests . "</li></ul>";
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "mail.host.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "info@host.com"; // SMTP username
$mail->Password = "123456"; // SMTP password
$mail->IsHTML(true);
$mail->From = "info@host.com";
$mail->Fromname = "John Doe";
$mail->AddAddress("info@gmail.com","John Doe");
$mail->Subject = $_POST['content'];
$mail->Body = $message;
if(!$mail->Send())
{
echo "Mesagge not delivered <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message sent";
?>
后,您可以设置变量。
尝试:
$mail->AddAddress = ("info@gmail.com","John Doe");
此外,我不认为使用net::ERR_CONTENT_LENGTH_MISMATCH
会有效,不确定......
..也许它确实如此!我答案中的上述方法肯定应该适用于xD!
答案 1 :(得分:-1)
你得到的错误是什么?它从哪里开始产生错误? $ mail-&gt; AddAddress(“info@gmail.com”,“John Doe”)没有“=”符号。
所以它应该是:
$mail->AddAddress = ("info@gmail.com","John Doe");
另外,您可以将html添加到正文中,以便它看起来更好一些:
$mail->Body = "<html><body>";
$mail->Body .= "<table><tbody>";
$mail->Body .= "<tr><td>".$arrival_date."</td></tr>";
$mail->Body .= "</tbody></table>";
$mail->Body .= "</body></html>";