Possible Duplicate:
Having trouble with PHPMailerPHPMailer的發送Gmail SMTP超時
有很多類似的問題,但沒有人幫助我。
這裏是我的腳本在PHPMailer的exmaples提供:
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("some message");
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
和這裏的錯誤:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host.
在許多問題有人提到讓php_openssl extenstion
這是在我的服務器啓用。我使用的PHPMailer 5.1版
也有我的服務器的25端口,簡單mail()
功能沒有問題的正常工作
感謝您的幫助
從同一臺服務器ping主機\端口,以防萬一網絡問題 – 2012-11-26 22:26:50
@Dagon:ping沒有問題。我也嘗試在本地主機上,並有同樣的問題。我幾個月前使用這種方法發送了很多電子郵件,並且工作正常,但現在我已經忘記了如何... – Aliweb