无法使用PHPMailer_v5.1通过Gmail发送电子邮件 [英] Unable to send email through gmail using PHPMailer_v5.1

查看:193
本文介绍了无法使用PHPMailer_v5.1通过Gmail发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



获取以下错误,

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



以下是随PHPMailer下载的代码,我只是修改了
必填字段,

 <?php 
require_once('../ class.phpmailer.php') ;
//include(\"class.smtp.php); //可选,如果尚未加载,则从class.phpmailer.php中调用

$ mail = new PHPMailer(true); //真正的参数意味着它会抛出错误的异常,我们需要捕获

$ mail-> IsSMTP(); //告诉类使用SMTP

尝试{
$ mail-> Host =mail.yourdomain.com; // SMTP服务器
$ mail-> SMTPDebug = 2; //启用SMTP调试信息(用于测试)
$ mail-> SMTPAuth = true; //启用SMTP认证
$ mail-> SMTPSecure =ssl; //为服务器设置前缀
$ mail-> Host =smtp.gmail.com; //将GMAIL设置为SMTP服务器
$ mail->端口= 465; //设置GMAIL服务器的SMTP端口
$ mail->用户名=santosh1984naidu@gmail.com; // GMAIL用户名
$ mail->密码=********; // GMAIL密码
$ mail-> AddReplyTo('antantosh1984naidu@gmail.com','First Last');
$ mail-> AddAddress('antantosh1984naidu@gmail.com','John Doe');
$ mail-> SetFrom('antantosh1984naidu@gmail.com','First Last');
$ mail-> AddReplyTo('antantosh1984naidu@gmail.com','First Last');
$ mail-> Subject ='PHPMailer通过邮件测试主题(),高级';
$ mail-> AltBody ='要查看邮件,请使用兼容HTML的电子邮件查看器!'; //可选 - MsgHTML将自动创建一个备用
$ mail-> MsgHTML(file_get_contents('contents.html'));
$ mail-> AddAttachment('images / phpmailer.gif'); //附件
$ mail-> AddAttachment('images / phpmailer_mini.gif'); //附件
$ mail->发送();
echoMessage Sent OK< / p> \\\
;
} catch(phpmailerException $ e){
echo $ e-> errorMessage(); //漂亮错误消息来自PHPMailer
} catch(Exception $ e){
echo $ e-> getMessage(); / /从其他任何烦人的错误信息!
}
?>


解决方案

基于错误,似乎SSL未启用在PHP中。关闭我的头顶我相信你需要取消注释

extension = PHP_openssl.dll

在您的php.ini文件



以下内容可帮助您安装SSL,前提是系统已安装SSL: a href =http://us2.php.net/manual/en/openssl.installation.php =noreferrer> http://us2.php.net/manual/en/openssl.installation.php


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

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.

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

<?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!
    }
    ?>

解决方案

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

extension = PHP_openssl.dll

in your php.ini file

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

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

这篇关于无法使用PHPMailer_v5.1通过Gmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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