我得到这个错误PHP Fatal error: Call to a member function Send() on a non-object
。此错误与行有关if(!$mail->Send())
。
我在另一个论坛上搜索,它可能是关于在某处使用“load->”,但我不确定为什么以及如何。
function New_Mail($email,$firstname,$surname,$body, $subject, $altBody, $wordwrap){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "xxxxxxx@gmail.com"; // GMAIL username
$mail->Password = "xxxxx"; // GMAIL password
$mail->From = "xxxxxxx@gmail.com";
$mail->FromName = "Admin";
$mail->Subject = $subject;
$mail->AltBody = $altBody;//Text Body
$mail->WordWrap = $wordwrap; // set word wrap
$mail->AddAddress($email,$firstname." ".$surname);
$mail->MsgHTML($body);
$mail->AddReplyTo("replyto@yourdomain.com","Admin");
$mail->SMTPDebug = 1;
$mail->IsHTML(true); // send as HTML
}
$mail=New_Mail($email,$firstname,$surname,'This is the body','Welcome','this is the alternate body',100);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
// nothing is displayed
}