我想用phpMailer通過電子郵件向用戶發送確認消息。我的代碼是這樣的:PHPMailer將Gmail用作SMTP服務器。不能連接到SMTP主機。郵件錯誤:SMTP錯誤:無法連接到SMTP主機
<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // your SMTP username or your gmail username
$mail->Password = "mypasswrord"; // your SMTP password or your gmail password
$from = "[email protected]"; // Reply to this email
$to="[email protected]"; // Recipients email ID
$name="Jersey Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
我已經在php.ini中啓用了SSL。
PS> [email protected]是保護隱私的掩碼郵件。但我沒有把一個真實的電子郵件地址,在該部分
你有沒有考慮使用http://swiftmailer.org/?它可以通過GMail發送電子郵件。大圖書館! :-) – Flukey 2011-05-29 16:33:10
此外,將主機從「ssl://smtp.gmail.com」更改爲「smtp.gmail.com」 – Flukey 2011-05-29 16:37:14
什麼都沒有發生..甚至沒有回聲 – phpDeveloperForThesis 2011-05-29 16:50:36