我想使用 Mandrill 发送电子邮件。我正在定制我的phpmailer,我曾经用它来发送邮件与mandrill phpmailer。(在这里找到: http://help.mandrill.com/entries/23737696-How-do-I-send-with-PHPMailer- (
require 'mandrillmailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from@example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress($to); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
echo $mail->Subject;
//$mail->Send();
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'hiii';
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else{
echo 'hello';
echo 'Message has been sent';
}
die('here');
我没有收到回复消息,即电子邮件是否已发送。我调试了它被回显语句卡住的地方。我可以在echo $mail->Subject;
之前看到消息,但不能超过此范围。我猜$mail->Send()
不起作用,这就是为什么超出该范围的消息不显示并且电子邮件发送不起作用的原因。
我该如何解决这个问题?
假设您已经输入了正确的授权,请尝试使用自动加载器而不是 phpmailer 类。这对我有用:
require 'mandrillmailer/PHPMailerAutoload.php';
或者,您可以尝试一些更简单的方法。类似于官方Mandrill PHP客户端或像sendwithus这样的独立服务。
首先检查 PHPMailer 类版本 如果低于版本 5,则使用最新版本 5.2.9使用版本 5.2.9 时我的问题已解决