簡體   English   中英

使用PHPMailer和GMAIL SMTP發送電子郵件

[英]Sending an email using PHPMailer and GMAIL SMTP

我已經在網絡上閱讀了每個示例,但似乎仍然無法連接到GMAIL SMTP。 這是我正在運行的代碼:

include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail@gmail.com"; //Reply to this email ID
$email="someone@gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
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";
}

我嘗試在此處設置端口,並且在class.smtp.php文件中也進行了以下設置:

$host = "ssl://smtp.gmail.com";
$port = 465;

我不斷收到相同的錯誤,並確保已啟用ssl。 我得到的錯誤是:

SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)

如前所述,我已經通過擺脫ssl來啟用了ssl; 與php_openssl.dll並重新啟動Apache。 我做了一些閱讀,發現啟用命令之前還有一些人[PHP_OPENSSL]。 我添加了它並重新啟動了Apache,一切正常! 感謝所有的評論

在php.ini中:

[PHP_OPENSSL]
extension=php_openssl.dll

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM