无法使用PHPMailer通过Google SMTP发送邮件

时间:2022-01-29 23:14:25

I'm trying to send out mail using Google's SMTP in combination with PHPMailer, but I can't get it to work. This is my code:

我正在尝试使用Google的SMTP与PHPMailer一起发送邮件,但我无法让它发挥作用。这是我的代码:

$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "myemail@gmail.com";
$mail->Password = "**********";
$mail->Port = "465";

First I do not fully understand what should be filled in as 'SMTPSecure', some say 'ssl', other say 'tls'. Next for 'Port' I could enter '465' or '587'. But none of the combinations work... Note that I'm using a regular Gmail account and not Google Apps. In my Gmail account I've enabled 'POP access'.

首先,我不完全理解应该填写什么作为'SMTPSecure',有人说'ssl',其他人说'tls'。接下来的'Port'我可以输入'465'或'587'。但是这些组合都不起作用......请注意,我使用的是常规Gmail帐户,而不是Google Apps。在我的Gmail帐户中,我启用了“POP访问”。

The error I get is: "Must issue a STARTTLS command first". Which means SSL failed, but don't know why...

我得到的错误是:“必须首先发出STARTTLS命令”。这意味着SSL失败了,但不知道为什么......

5 个解决方案

#1


Ok, the problem was the version of PHPMailer. I updated to PHPMailer version 5 and everything worked great. I was using phpMailer version 1.02.

好的,问题是PHPMailer的版本。我更新到PHPMailer版本5,一切都很好。我使用的是phpMailer 1.02版。

#2


I had similar problems with GMail when using it through CodeIgniter

通过CodeIgniter使用GMail时,我遇到了类似的问题

For me, changing the host option worked:

对我来说,更改主机选项有效:

$mail->Host = "ssl://smtp.googlemail.com";

#3


Set $mail->SMTPDebug = 1; It will give you more info about this error. Most likely you will get "Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP". To fix this remove ";" from ;extension=php_openssl.dll line in php.ini.

设置$ mail-> SMTPDebug = 1;它将为您提供有关此错误的更多信息。很可能你会得到“无法找到套接字传输”ssl“ - 你在配置PHP时忘了启用它”。要解决此问题,请删除“;” from; extension = php.ini中的php_openssl.dll行。

PS I also like XAMPP :)))

PS我也喜欢XAMPP :)))

#4


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

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

I changed from SSL to ssl. It works.

我从SSL改为ssl。有用。

#5


According to this post here, Google may not be offering this service any more:

根据这篇文章,Google可能不再提供此服务:

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

#1


Ok, the problem was the version of PHPMailer. I updated to PHPMailer version 5 and everything worked great. I was using phpMailer version 1.02.

好的,问题是PHPMailer的版本。我更新到PHPMailer版本5,一切都很好。我使用的是phpMailer 1.02版。

#2


I had similar problems with GMail when using it through CodeIgniter

通过CodeIgniter使用GMail时,我遇到了类似的问题

For me, changing the host option worked:

对我来说,更改主机选项有效:

$mail->Host = "ssl://smtp.googlemail.com";

#3


Set $mail->SMTPDebug = 1; It will give you more info about this error. Most likely you will get "Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP". To fix this remove ";" from ;extension=php_openssl.dll line in php.ini.

设置$ mail-> SMTPDebug = 1;它将为您提供有关此错误的更多信息。很可能你会得到“无法找到套接字传输”ssl“ - 你在配置PHP时忘了启用它”。要解决此问题,请删除“;” from; extension = php.ini中的php_openssl.dll行。

PS I also like XAMPP :)))

PS我也喜欢XAMPP :)))

#4


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

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

I changed from SSL to ssl. It works.

我从SSL改为ssl。有用。

#5


According to this post here, Google may not be offering this service any more:

根据这篇文章,Google可能不再提供此服务:

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/