php Codeigniter:SMTP 邮件不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14508815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter: SMTP mail not working
提问by Luis Martin
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.
我正在尝试设置联系表单,但我正在努力使其与 CI 中的 SMTP 配置一起工作。但是我已经成功地尝试了基本的“邮件”配置。
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' => '[email protected]',
'smtp_pass' => '********',
'mailtype' => 'text',
'charset' => 'utf-8',
'wordwrap' => true,
'wrapchars' => 50
);
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('[email protected]');
$this->email->to('[email protected]');
$this->email->reply_to('[email protected]', '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.
我刚刚问过我的托管服务提供商,所有 SMTP 配置都是正确的。他们还检查了我的电子邮件帐户是否正常工作。
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.
消息传递没有问题。AFAIK php mail() 函数也使用托管服务提供商 SMTP,但它只是将它交给服务器并忘记它。
Instead I'd like to use SMTP authentication, which worries about the dispatch of the e-mail. But only by changing
相反,我想使用 SMTP 身份验证,它担心电子邮件的发送。但只有改变
protocol => 'smtp'
协议 => '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: <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Reply-To: "John Doe" <[email protected]>
Subject: =?utf-8?Q?Message_sent_from_the_contact_form_in_website?=
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
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?
这个错误的原因可能是什么?
回答by stormdrain
Some have reported 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 => maildoes not use your provider -- it will send the email directly from your server.
我很确定protocol => mail不使用您的提供商——它会直接从您的服务器发送电子邮件。
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).
如果不是单引号问题,则可能是凭据、防火墙或连接要求不正确(比如您的电子邮件提供商是否需要 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-Telnetor thunderbird or somesuch) to verify the protocols are correct.
尝试连接到邮件服务器并使用另一个客户端发送电子邮件(您可以使用 telnet:http: //www.wikihow.com/Send-Email-Using-Telnet或 Thunderbird 或类似的)来验证协议是否正确。

