我正在尝试通过PHPMailer发送电子邮件。我已经将 PHPMailer 文件解压缩到服务器并拥有此代码。我有额外的"要求",因为其他帖子中已经建议发送时悬挂。
它正在阅读代码,就好像我错过了"正文"一样,我会收到一条错误消息。
我已经尝试了多个不同代码的示例,如下所示,并且都挂起了。我已经添加和更改了,现在放弃了!我有一个简单的按钮可以调用此代码,浏览器(尝试多个)只是挂起。知道我做错了什么吗?
require 'PHPMailer/PHPMailerAutoload.php';
require 'PHPMailer/class.smtp.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.eastlink.ca'; // Specify main and backup SMTP servers
$mail->Username = 'ns@eastlink.ca'; // SMTP username
$mail->Password = '*******'; // SMTP password
$mail->From = 'ns@eastlink.ca';
$mail->FromName = 'bob';
$mail->addAddress('dsmith@eastlink.ca', 'D'); // Add a recipient
$mail->addReplyTo('ns@eastlink.ca', 'Information');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
您似乎没有指定端口
尝试添加:
$mail->SMTPAuth = true;
$mail->Port = 25;
请参阅:http://my.eastlink.ca/customersupport/internet/faqs/email.aspx
根据EastLink Doc的说法,当与无线设备连接(不共享)时:
服务器类型:SMTP端口:465 或 587服务器名称:smtp.eastlink.ca使用 STARTTLS
所以试试:
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
// OR
$mail->SMTPSecure = 'tls';