Home Articles

使用Wamp在codeigniter中发送电子邮件时出错

Asked
Viewed 1393 times
0

我正在尝试使用WAMP localhost从我的gmail id发送电子邮件到codeigniter的另一个电子邮件ID .

我收到以下错误

hello:F遇到以下SMTP错误:F无法使用PHP SMTP发送电子邮件 . 您的服务器可能未配置为使用此方法发送邮件 .

这是我的控制器功能中的电子邮件发送代码

$config['useragent']    = 'CodeIgniter';
        $config['protocol']     = 'smtp';
        $config['smtp_host']    = 'smtp.gmail.com';
        $config['smtp_user']    = 'myemail@gmail.com'; // Your gmail id
        $config['smtp_pass']    = '****'; // Your gmail Password
        $config['smtp_port']    = 465;
     //   $config['mailpath'] = 'D:\wamp64\sendmail';
       // $config['smtp_timeout']='30';
        $config['wordwrap']     = TRUE;
        $config['wrapchars']    = 76;
        $config['mailtype']     = 'html';
        $config['charset']      = 'iso-8859-1';
        $config['validate']     = FALSE;
        $config['priority']     = 3;
        $config['newline']      = "\r\n";
        $config['crlf']         = "\r\n";
      //  $config['smtp_crypto']      = 'ssl';

        $this->load->library('email');
        $this->email->initialize($config);

        $this->email->from('myemail@gmail.com', 'Sana Riaz');
        $this->email->to('myemail@gmail.com');

        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');

        //$this->email->send();

        if($this->email->send()){
            echo "sent";

        }else
            show_error($this->email->print_debugger());

这些是我在 php.ini 文件中所做的设置,这些设置在旧帖子中提出 .

extension=php_openssl.dll

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo ="D:\wamp64\bin\mariadb\mariadb10.2.8\mysql-test\std_data\cacert.pem"

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile="D:\wamp64\bin\mariadb\mariadb10.2.8\mysql-test\std_data\cacert.pem"


[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from ="myemail@gmail.com"

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path ="D:\wamp64\sendmail\sendmail.exe -t"

这些是我尝试的其他东西也没有用

  • 使用sendmail和mail而不是 $config['protocol'] = 'smtp'; 分别产生以下错误

(邮件)

无法使用PHP mail()发送电子邮件 . 您的服务器可能未配置为使用此方法发送邮件 .

(发邮件)

退出状态代码:1无法打开Sendmail的套接字 . 请检查设置 . 无法使用PHP Sendmail发送电子邮件 . 您的服务器可能未配置为使用此方法发送邮件 .

  • 将端口465更改为25和587,这会产生以下错误

220 smtp.gmail.com ESMTP v78sm12109697wmv.27 - gsmtp

  • 添加 $config['smtp_crypto'] = 'ssl'; 会产生以下错误

fsockopen():SSL操作失败,代码为1. OpenSSL错误消息:错误:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议

  • 禁用防火墙,防病毒等

  • 从Gmail帐户启用 IMAPPOP

我不知道我做错了什么或我错过了什么 . 任何建议都会极为有用

这些是我之前遇到的一些帖子,但是没有用过

1 Answer

  • 0

    像localhost一样发送邮件localy需要一个邮件服务器,例如Fake SendMail .

    由于Google Mail已更改其SSL安全性并删除了对Sendmail.exe使用的v2的支持,因此将配置其GMail帐户的用户也需要配置Stunnel .

    What you'll need:

    • WAMP Server 64位

    • Fake Sendmail for Windows

    • 任何电子邮件提供商的电子邮件帐户,我正在使用GMail帐户 .

    • Stunnel(如果假Sendmail itselft不起作用)

    sendmail.ini 设置将按以下方式完成:

    smtp_server=smtp.gmail.com # if gmail, if configured with stunnel use localhost
    smtp_port=465 # if gmail, if configured with stunnel use 25
    smtp_ssl=auto # if gmail, if configured with stunnel use none
    auth_username=youremail@gmail.com
    auth_password=yourpassword
    

    有关 Stunnel 配置和更多信息,请参阅CONFIGURE SENDMAIL WITH WAMP

Related