简体   繁体   English

在Codeigniter中发送电子邮件时出错

[英]Error in sending email in codeigniter

I am using following configuration for sending mail through php mail function : 我正在使用以下配置通过php邮件功能发送邮件:

function sendInvoiceEmail() {

GET CUSTOMER EMAIL 获取客户电子邮件

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

CREATE EMAIL CONFIGURATION ARRAY 创建电子邮件配置数组

    $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',
        );

Set your email information 设置您的电子邮件信息

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

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

        $message = "Test Message for Invoice";

Load CodeIgniter Email library 加载CodeIgniter电子邮件库

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

Sometimes you have to set the new line character for better result 有时您必须设置换行符才能获得更好的结果

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

Set email preferences 设置电子邮件首选项

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

Ready to send email and check whether the email was successfully sent 准备发送电子邮件并检查电子邮件是否已成功发送

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

I am having PHP 5.3.9 version and wampserver but I am getting following error : 我有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 

send mail using this method. 使用此方法发送邮件。

Try changing the "smtp_host" to " smtp.gmail.com " 尝试将“ smtp_host”更改为“ smtp.gmail.com

Check out: SMTP Error: Could not connect to SMTP host 签出: SMTP错误:无法连接到SMTP主机

Try checking the SSL error: 尝试检查SSL错误:

From the error it looks like your version of PHP might not have been compiled with ssl. 从该错误看来,您的PHP版本可能未使用ssl进行编译。

Run: 跑:

<?php
phpinfo();
?>

And check if the "Configure Command" has something like "--with-openssl=/usr". 并检查“配置命令”是否具有“ --with-openssl = / usr”之类的内容。 Also check that you have ssl listed in the "Registered Stream Socket Transports" section. 另外,还要检查“已注册的流套接字传输”部分中是否列出了ssl。

I know about wampserver there is setting in PHP Extension so if you are using wampserver then you can do the following step : 我知道wampserver,PHP扩展中有设置,因此如果您使用wampserver,则可以执行以下步骤:

1) Go to WampSever Tray icon 1)转到WampSever托盘图标

2) Go to PHP Extension 2)转到PHP扩展

3) Search for php_openssl 3)搜索php_openssl

4) If it is not checked then mark it as checked ( php_openssl ) 4)如果未选中,则将其标记为选中( php_openssl

Otherwise you can refer Michael's answer :) 否则,您可以参考迈克尔的答案:)

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM