无法使用PHPMailer_v5.1通过gmail发送电子邮件

时间:2021-12-29 18:15:38

I am trying to send email through gmail using PHPMailer_V5.1.

我正在尝试使用PHPMailer_V5.1通过gmail发送电子邮件。

Getting the following error,

得到以下错误,

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (41961176) SMTP Error: Could not connect to SMTP host.

SMTP ->错误:连接到服务器失败:无法找到套接字传输“ssl”——在配置PHP时是否忘记启用它?(41961176) SMTP错误:无法连接SMTP主机。

The following is the code which came with the PHPMailer download, I just modified the required fields,

下面是随PHPMailer下载而来的代码,我刚刚修改了必需的字段,

<?php
    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->Host       = "mail.yourdomain.com"; // SMTP server
      $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   = "santosh1984naidu@gmail.com";  // GMAIL username
      $mail->Password   = "********";            // GMAIL password
      $mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
      $mail->AddAddress('santosh1984naidu@gmail.com', 'John Doe');
      $mail->SetFrom('santosh1984naidu@gmail.com', 'First Last');
      $mail->AddReplyTo('santosh1984naidu@gmail.com', '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(file_get_contents('contents.html'));
      $mail->AddAttachment('images/phpmailer.gif');      // attachment
      $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
      $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!
    }
    ?>

2 个解决方案

#1


8  

Based on the error it seems that SSL is not enabled in PHP. Off the top of my head I believe that you need to uncomment

基于错误,在PHP中似乎没有启用SSL。在我的脑海中,我相信你需要停止评论

extension = PHP_openssl.dll

扩展= PHP_openssl.dll

in your php.ini file

在php。ini文件

Following should help you install SSL if it is already setup on your system:

如果SSL已经安装在您的系统上,以下内容应该可以帮助您安装:

http://us2.php.net/manual/en/openssl.installation.php

http://us2.php.net/manual/en/openssl.installation.php

#2


0  

Well, the error message says it all:

错误信息说明了一切

Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

无法找到套接字传输“ssl”——在配置PHP时是否忘记启用它?

It means that the PHP version is not equipped with the necessary libraries to communicate with the mail server (or any other server for that matter) through SSL.

这意味着PHP版本没有配备必要的库来通过SSL与邮件服务器(或任何其他服务器)通信。

If you don't have root access to your server, this is probably an issue for your server administrator / provider.

如果您没有对服务器的根访问权,这可能是服务器管理员/提供者的问题。

From a similar discussion in a forum, a possible solution that sounds quite realistic:

在一个论坛的类似讨论中,一个可能的解决方案听起来相当现实:

My guess is that either mod_ssl is not installed for apache or it is installed but the configuration lines for mod_ssl are commented out in httpd.conf (like it was on suse9 for me). apxs will only enable ssl functions in php if mod_ssl is up and running

我的猜测是,要么mod_ssl不是为apache安装的,要么它已经安装了,但是mod_ssl的配置行是在httpd中注释掉的。conf(就像对我的suse9)。apxs只在mod_ssl启动并运行时才启用php中的ssl函数

So check mod_ssl is available + enabled in apache then try recompiling php with

因此,检查mod_ssl在apache中是否启用+,然后尝试重新编译php

./configure --with-apxs2=/usr/sbin/apxs --with-mysql --enable-ssl

. / configure——with-apxs2 = / usr / sbin / apx型——在mysql——启用ssl

#1


8  

Based on the error it seems that SSL is not enabled in PHP. Off the top of my head I believe that you need to uncomment

基于错误,在PHP中似乎没有启用SSL。在我的脑海中,我相信你需要停止评论

extension = PHP_openssl.dll

扩展= PHP_openssl.dll

in your php.ini file

在php。ini文件

Following should help you install SSL if it is already setup on your system:

如果SSL已经安装在您的系统上,以下内容应该可以帮助您安装:

http://us2.php.net/manual/en/openssl.installation.php

http://us2.php.net/manual/en/openssl.installation.php

#2


0  

Well, the error message says it all:

错误信息说明了一切

Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

无法找到套接字传输“ssl”——在配置PHP时是否忘记启用它?

It means that the PHP version is not equipped with the necessary libraries to communicate with the mail server (or any other server for that matter) through SSL.

这意味着PHP版本没有配备必要的库来通过SSL与邮件服务器(或任何其他服务器)通信。

If you don't have root access to your server, this is probably an issue for your server administrator / provider.

如果您没有对服务器的根访问权,这可能是服务器管理员/提供者的问题。

From a similar discussion in a forum, a possible solution that sounds quite realistic:

在一个论坛的类似讨论中,一个可能的解决方案听起来相当现实:

My guess is that either mod_ssl is not installed for apache or it is installed but the configuration lines for mod_ssl are commented out in httpd.conf (like it was on suse9 for me). apxs will only enable ssl functions in php if mod_ssl is up and running

我的猜测是,要么mod_ssl不是为apache安装的,要么它已经安装了,但是mod_ssl的配置行是在httpd中注释掉的。conf(就像对我的suse9)。apxs只在mod_ssl启动并运行时才启用php中的ssl函数

So check mod_ssl is available + enabled in apache then try recompiling php with

因此,检查mod_ssl在apache中是否启用+,然后尝试重新编译php

./configure --with-apxs2=/usr/sbin/apxs --with-mysql --enable-ssl

. / configure——with-apxs2 = / usr / sbin / apx型——在mysql——启用ssl