【发布时间】:2016-08-25 12:03:15
【问题描述】:
尝试使用 SMTP 从窗口服务器发送邮件。 我得到这个错误
Fatal error: Class 'SMTP' not found in...
当我只使用 PHPmailerAutoload.php 时它会给出
Fatal error: Call to undefined method SMTP::setDebugLevel() in...
我的代码是
error_reporting(E_ALL);
ini_set('display_errors','1');
require_once('class.phpmailer.php');
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = "mail.host.com.au";
$mail->Port = 25;
$mail->Username = "myusername";
$mail->Password = "mypassword";
$mail->SetFrom('info@company.com.au', 'First Last');
$mail->AddReplyTo("info@company.com.au","First Last");
$mail->Subject = "PHPMailer Test Subject";
$body = "test";
$mail->MsgHTML($body);
$address = "myemail@gmail.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
请提供任何建议。
【问题讨论】:
-
你在这一行错过了
"替换$mail->Subject = "PHPMailer Test Subject"; -
将 SMTPDebug 设置为 false
$mail->SMTPDebug = false; -
没有发生同样的错误显示...
-
我的代码很完美,然后我在谷歌上看到有几个版本的 phpmailer 类可用,所以我尝试了不同的版本,它工作了。
-
感谢您的宝贵时间。
标签: php email smtp phpmailer smtp-auth