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

无法使用PHPMailer_v5.1通过gmail发送电子邮件,php,gmail,phpmailer,Php,Gmail,Phpmailer,我正在尝试使用PHPMailer_V5.1通过gmail发送电子邮件 获取以下错误 SMTP->错误:无法连接到服务器:找不到套接字传输ssl-配置PHP时是否忘记启用它?41961176 SMTP错误:无法连接到SMTP主机 以下是PHPMailer下载时附带的代码,我刚刚修改了 必填字段 <?php require_once('../class.phpmailer.php'); //include("class.smtp.php"); // optional, gets

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

获取以下错误

SMTP->错误:无法连接到服务器:找不到套接字传输ssl-配置PHP时是否忘记启用它?41961176 SMTP错误:无法连接到SMTP主机

以下是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!
    }
    ?>

嗯,错误消息说明了这一切:

找不到套接字传输ssl-配置PHP时是否忘记启用它

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

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

从一个角度来看,这是一个听起来非常现实的可能解决方案:

我猜要么是apache没有安装mod_ssl,要么是安装了 已安装,但mod_ssl的配置行已在中注释掉 httpd.conf就像我在suse9上看到的一样。apxs将只启用ssl 如果mod_ssl已启动并正在运行,则在php中使用函数

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

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


嗯,错误消息说明了这一切:

找不到套接字传输ssl-配置PHP时是否忘记启用它

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

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

从一个角度来看,这是一个听起来非常现实的可能解决方案:

我猜要么是apache没有安装mod_ssl,要么是安装了 已安装,但mod_ssl的配置行已在中注释掉 httpd.conf就像我在suse9上看到的一样。apxs将只启用ssl 如果mod_ssl已启动并正在运行,则在php中使用函数

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

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


根据错误,PHP中似乎未启用SSL。在我的脑海里,我相信你需要取消注释

extension=PHP\u openssl.dll

在php.ini文件中

如果您的系统上已经安装了SSL,则以下内容应有助于您安装SSL:


根据错误,PHP中似乎未启用SSL。在我的脑海里,我相信你需要取消注释

extension=PHP\u openssl.dll

在php.ini文件中

如果您的系统上已经安装了SSL,则以下内容应有助于您安装SSL:


您似乎在顶部将主机设置为mail.yourdomain.com。试着删除它,看看是否有帮助。不,删除它没有任何区别。你似乎在顶部将主机设置为mail.yourdomain.com。试着删除它,看看是否有帮助。否删除它没有任何区别我取消了LoadModule ssl\u module modules/mod\u ssl.so的注释,并重新启动,但没有更改,我仍然收到错误。如何检查mod_ssl是否可用?我认为您还必须使用-enable ssl重新编译PHP。查看phoinfo;首先看看PHP是如何编译的。@San:您还需要在PHP中启用支持,我想正如Waleed在上游提到的那样。注意,他给出了有关扩展名的windows特定指令,该扩展名应为.so,在*nix框中。我取消了LoadModule ssl\u module modules/mod\u ssl.so的注释,并重新启动,但没有更改,我仍然收到错误。如何检查mod_ssl是否可用?我认为您还必须使用-enable ssl重新编译PHP。查看phoinfo;首先看看PHP是如何编译的。@San:您还需要在PHP中启用支持,我想正如Waleed在上游提到的那样。注意,他给出了特定于windows的指令,以引用扩展名,它应该是一个。因此在*nix box.wow..uncommenting extension=PHP_openssl.dll上工作正常。我不明白为什么会被评论。这是我编写php代码的第一天,我有很多东西要学习,有些功能默认是注释的。如果您查看php.ini,您将在其中找到几个。原因我不确定。我很高兴你让它工作了。哇..取消注释extension=PHP\u openssl.dll工作了。我不明白为什么会被评论。这是我编写php代码的第一天,我有很多东西要学习,有些功能默认是注释的。如果您查看php.ini,您将在其中找到几个。原因我不确定。不过我很高兴你让它工作了。