问题
I am trying to send an email via PHPMailer. I have unzipped the PHPMailer file to the server and have this code. I have the extra 'require' as it has been suggested in other posts regarding hanging when sending.
It is reading the code as if I miss out the 'body' I get an error message saying so.
I have tried multiple examples of different code as below and all hang. I have added and altered and now given up! I have a simple button that calls this code and the browser (tried multiple) just hangs. Any ideas what I am doing wrong?
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';
}
回答1:
You don't seem to specifying a port
Try adding:
$mail->SMTPAuth = true;
$mail->Port = 25;
See: http://my.eastlink.ca/customersupport/internet/faqs/email.aspx
According to EastLink Doc, when connected with wireless device (not shared):
Server Type: SMTP Port: 465 or 587 Server Name: smtp.eastlink.ca Use STARTTLS
So Try:
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
// OR
$mail->SMTPSecure = 'tls';
来源:https://stackoverflow.com/questions/35945391/phpmailer-hangs