Codeigniter:SMTP邮件不工作 [英] Codeigniter: SMTP mail not working

查看:139
本文介绍了Codeigniter:SMTP邮件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个联系表单,我正在努力使其在CI中配置SMTP配置。但是,我已经成功尝试使用基本的邮件配置。



为了简化,我正在使用这个简单的代码进行测试:

  $ config = array(
'protocol'=>'smtp',
'smtp_host'=>'smtp .1and1.es',
'smtp_port'=> 25,
'smtp_user'=>'user@mysite.com',
'smtp_pass'=>'*** *****',
'mailtype'=>'text',
'charset'=>'utf-8',
'wordwrap'=> true,
'wrapchars'=> 50
);

$ this-> load-> library('email');
$ this-> email-> initialize($ config); $(b)
$ b $ this-> email-> from('my_real_email_address@gmail.com');
$ this-> email-> to('my_real_email_address@gmail.com');
$ this-> email-> reply_to('my_real_email_address@gmail.com','John Doe');
$ this-> email->主题('从网站上的联系表格发送的消息);
$ this-> email-> message('Body of message ...');

if($ this-> email-> send()){
return true;
}
echo'<! - '。 print_r($ this-> email-> print_debugger(),true)。 - >;
返回false;

我刚刚问我的托管提供商,所有的SMTP配置是正确的。他们还检查了我的电子邮件帐户是否正常工作。



其实如果我选择:



协议=>'邮件'



消息传递没有问题。 AFAIK的php mail()功能也使用托管提供商SMTP,但它只是交给服务器并忘记它。



相反,我想使用SMTP认证,担心电子邮件的发送。但是,当我发送时,只能通过更改



protocol =>'smtp'



表单有很多处理时间,我终于得到这个调试信息:

  220 smtp.1and1.es(mreu2)欢迎到Nemesis ESMTP服务器

hello:遇到以下SMTP错误:
无法发送AUTH LOGIN命令。错误:421 smtp.1and1.es连接超时

从:遇到以下SMTP错误:
到:遇到以下SMTP错误:
数据:以下SMTP遇到错误:

遇到以下SMTP错误:
无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。
用户代理:CodeIgniter
日期:2013年1月24日,星期四18:51:31 +0100
来自:< my_real_email_address@gmail.com&
返回路径:< my_real_email_address@gmail.com&
至:my_real_email_address@gmail.com
回复:John Doe< my_real_email_address@gmail.com>
主题:=?utf-8?Q?Message_sent_from_the_contact_form_in_website?=
X发件人:my_real_email_address@gmail.com
X-Mailer:CodeIgniter
X优先级:3(正常)
Message-ID:< 510174a33158d@gmail.com&
Mime版本:1.0


内容类型:text / plain; charset = utf-8
内容传输编码:8bit

邮件正文...

这个错误可能是什么原因?

解决方案

这个家伙提到有一个带有单引号的配置项的问题:

  $ config ['crlf'] ='\r\\\
'; //应该是\r\\\

$ config ['newline'] ='\r\\\
'; //应该是\r\\\

我确定 protocol =>邮件不使用您的提供商 - 它将直接从您的服务器发送电子邮件。



如果不是单引号问题,这可能是不正确的凭据,防火墙或连接要求的问题(例如,如果您的电子邮件提供商需要TLS / SSL) p>

尝试连接到邮件服务器并与另一个客户端发送电子邮件(您可以使用telnet: http://www.wikihow.com/Send-Email-Using-Telnet 或thunderbird或somesuch)来验证协议是否正确。


I'm trying to set up a contact form, and I'm struggling to get it working with the SMTP configuration in CI. However I've successfully tried with the basic 'mail' config.

To cut it short, I'm doing my tests with this simple code:

    $config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'smtp.1and1.es',
        'smtp_port' => 25,
        'smtp_user' => 'user@mysite.com', 
        'smtp_pass' => '********',
        'mailtype'  => 'text',
        'charset'   => 'utf-8',
        'wordwrap'  => true,
        'wrapchars' => 50            
    );

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

    $this->email->from('my_real_email_address@gmail.com');
    $this->email->to('my_real_email_address@gmail.com');
    $this->email->reply_to('my_real_email_address@gmail.com', 'John Doe');
    $this->email->subject('Message sent from the contact form in website');
    $this->email->message('Body of message...');

    if ($this->email->send()) {
            return true;
    }
    echo '<!--' . print_r($this->email->print_debugger(), true) . '-->'; 
    return false;

I've just asked my hosting provider and all the SMTP config is correct. They've also checked my e-mail account is working properly.

In fact if I choose:

protocol => 'mail'

the message is delivered without problems. AFAIK the php mail() function also uses the hosting provider SMTP but it simply hands it over to the server and forgets it.

Instead I'd like to use SMTP authentication, which worries about the dispatch of the e-mail. But only by changing

protocol => 'smtp'

when I send the form there's a lot of processing time and I finally get this debugging message:

220 smtp.1and1.es (mreu2) Welcome to Nemesis ESMTP server

hello:  The following SMTP error was encountered:
Failed to send AUTH LOGIN command. Error: 421 smtp.1and1.es connection timed out

from:  The following SMTP error was encountered:
to:  The following SMTP error was encountered: 
data:  The following SMTP error was encountered:  

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.
User-Agent: CodeIgniter
Date: Thu, 24 Jan 2013 18:51:31 +0100
From: <my_real_email_address@gmail.com>
Return-Path: <my_real_email_address@gmail.com>
To: my_real_email_address@gmail.com
Reply-To: "John Doe" <my_real_email_address@gmail.com>
Subject: =?utf-8?Q?Message_sent_from_the_contact_form_in_website?=
X-Sender: my_real_email_address@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <510174a33158d@gmail.com>
Mime-Version: 1.0


Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Body of message...

What might be the reason of this error?

解决方案

This guy mentioned having an issue with a config item having single quotes:

$config['crlf'] = '\r\n';      //should be "\r\n"
$config['newline'] = '\r\n';   //should be "\r\n"

I'm pretty certain protocol => mail does not use your provider -- it will send the email directly from your server.

If it's not the single quote issue, it might be an issue with incorrect credentials, firewall or connection requirement (say if your email provider requires TLS/SSL).

Try connecting to the mail server and send an email with another client (you could use telnet: http://www.wikihow.com/Send-Email-Using-Telnet or thunderbird or somesuch) to verify the protocols are correct.

这篇关于Codeigniter:SMTP邮件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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