PHPMailer将Gmail用作SMTP服务器。不能连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机 [英] PHPMailer to use Gmail as SMTP server.Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host

查看:227
本文介绍了PHPMailer将Gmail用作SMTP服务器。不能连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用phpMailer通过电子邮件向用户发送确认消息。我的代码是这样的:

 <?php 
include(class.phpmailer.php);
include(class.smtp.php);
$ mail = new PHPMailer();
$ mail-> IsSMTP(); //设置邮件使用SMTP
$ mail-> Host =ssl://smtp.gmail.com; //指定主服务器和备份服务器
$ mail->端口= 465; //设置端口使用
$ mail-> SMTPAuth = true; //打开SMTP认证
$ mail->用户名=sender@gmail.com; //你的SMTP用户名或你的Gmail用户名
$ mail->密码=mypasswrord; //您的SMTP密码或您的Gmail密码
$ from =webmaster@example.com; //回复此电子邮件
$ to =receiver@yahoo.com; //收件人电子邮件ID
$ name =Jersey Name; //收件人姓名
$ mail->发件人= $ from;
$ mail-> FromName =网站管理员; //姓名以指示收件人收到
$ mail-> AddAddress($ to,$ name)时邮件的来源;
$ mail-> AddReplyTo($ from,Webmaster);
$ mail-> WordWrap = 50; //设置单词换行
$ mail-> IsHTML(true); //以HTML格式发送
$ mail-> Subject =使用Gmail从Php发送电子邮件;
$ mail-> Body =通过phpmailer发送这封电子邮件,这是HTML BODY; // HTML Body
$ mail-> AltBody =这是用户以纯文本格式查看时的主体; //文本正文
if(!$ mail-> Send())
{
echo邮件错误:。 $ MAIL-> ERRORINFO;
}
else
{
echoMessage has been sent;
}
?>

我已经在php.ini中启用了ssl。



PS> sender@gmail.com是保护隐私的掩码邮件。但我确实在该部分输入了真实的电子邮件地址

解决方案

在您的php.ini中,确保您已取消注释

  extension = php_openssl.dll 


i am trying to use phpMailer to send confirmation messages to users via email. my code is this:

<?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 = "sender@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "mypasswrord"; // your SMTP password or your gmail password
$from = "webmaster@example.com"; // Reply to this email
$to="receiver@yahoo.com"; // 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";
}
?>

i already enabled ssl in php.ini.

PS> sender@gmail.com is a mask email to protect the privacy. but i did put a true email address in that part

解决方案

in you php.ini make sure you have uncommented the line with

extension=php_openssl.dll

这篇关于PHPMailer将Gmail用作SMTP服务器。不能连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆