【问题标题】:Error in sending email in codeigniter在 codeigniter 中发送电子邮件时出错
【发布时间】:2012-12-12 19:16:02
【问题描述】:

我正在使用以下配置通过 php 邮件功能发送邮件:

function sendInvoiceEmail() {

获取客户电子邮件

        $recieverEmail = xyz@test.com; //Valid Email ID
        $recieverName = xyz; 

创建电子邮件配置数组

    $emailConfig = array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'abc@abc.com',   //Valid Email ID
            'smtp_pass' => 'password',      //Valid password
            'mailtype' => 'html', //text or html
            'charset' => 'iso-8859-1',
        );

设置您的电子邮件信息

        $from = array('email' => 'abc@abc.com', 'name' => 'Testing');

    $to = array('email' => $recieverEmail, 'name' => $recieverName);
        $subject = "Test Mail for Invoice ";

        $message = "Test Message for Invoice";

加载 CodeIgniter 电子邮件库

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

有时您必须设置换行符以获得更好的结果

        $this->email->set_newline("\r\n");

设置电子邮件首选项

        $this->email->from($from['email'], $from['name']);
        $this->email->to($to['email'], $to['name']);
        $this->email->subject($subject);
        $this->email->message($message);

准备发送邮件,检查邮件是否发送成功

        if ($this->email->send()) {
            return true;
        } else {
            show_error($this->email->print_debugger());                
        }
    }

我有 PHP 5.3.9 版本和 wampserver 但我收到以下错误:

An Error Was Encountered

The following SMTP error was encountered: 52770504 Unable to find the socket 
transport "ssl" - did you forget to enable it when you configured PHP?
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error:
Unable to send data: MAIL FROM:

from: 

The following SMTP error was encountered:
Unable to send data: RCPT TO:

to: 

The following SMTP error was encountered:
Unable to send data: DATA

data: 

The following SMTP error was encountered:
Unable to send data: User-Agent: CodeIgniter Date: Thu, 27 Dec 2012 16:50:28 
+0530 From: "Invoice Tester" Return-Path: To: df@df.kl Subject: =?iso-8859-1?Q?Test_Mail_for_Invoice_?= Reply-To: "sujit.singh@xpointers.com" X-Sender: sujit.singh@xpointers.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <50dc2efca4149@xpointers.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_50dc2efca4160" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_50dc2efca4160 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Test Message for Invoice --B_ALT_50dc2efca4160 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Test Message for Invoice --B_ALT_50dc2efca4160--
Unable to send data: .

The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to 

使用此方法发送邮件。

【问题讨论】:

  • 请发布您使用的操作系统。

标签: php codeigniter email


【解决方案1】:

尝试将“smtp_host”更改为“smtp.gmail.com

查看:SMTP Error: Could not connect to SMTP host

尝试检查 SSL 错误:

从错误看来,您的 PHP 版本可能没有使用 ssl 编译。

运行:

<?php
phpinfo();
?>

并检查“配置命令”是否有类似“--with-openssl=/usr”的内容。 还要检查您是否在“Registered Stream Socket Transports”部分列出了 ssl。

【讨论】:

  • 我的配置命令显示如下:cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--disable-isapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=D:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static" "--disable-static-analyze"
  • 那可能已经被切断了。里面有“ssl”吗?你能告诉我注册的流套接字传输吗?
  • 对不起,我怎样才能找到:注册的流套接字传输??
  • 我在注册流套接字传输中得到了这个:tcp、udp、ssl、sslv3、sslv2、tls
  • 好的,这意味着你有一个错误的网址。您是否尝试更改 smtp_host 的 url?
【解决方案2】:

我知道 wampserver 在 PHP 扩展中有设置,所以如果您使用 wampserver,那么您可以执行以下步骤:

1) 转到 WampSever 托盘图标

2) 转到 PHP 扩展

3) 搜索php_openssl

4) 如果未选中,则将其标记为已选中 (php_openssl)

否则你可以参考迈克尔的回答:)

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2012-11-21
    • 1970-01-01
    • 2018-06-18
    • 2012-12-26
    相关资源
    最近更新 更多