我正在尝试设置联系表单,我很难让它使用CI中的SMTP配置。但是我已经成功尝试了基本的'mail'配置。
简而言之,我正在使用这个简单的代码进行测试:
$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;
我刚刚问过我的托管服务提供商,所有的SMTP配置都是正确的。他们还检查了我的电子邮件帐户是否正常工作。
事实上,如果我选择:
protocol =>'mail'
消息传递没有问题。 AFAIK php mail()函数也使用托管服务提供商SMTP,但它只是将其交给服务器并忘记它。
相反,我想使用SMTP身份验证,担心发送电子邮件。但只能通过改变
protocol =>'smtp'
当我发送表单时有很多处理时间,我终于得到了这个调试信息:
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...
这个错误可能是什么原因?
This guy提到了具有单引号的配置项的问题:
$config['crlf'] = '\r\n'; //should be "\r\n"
$config['newline'] = '\r\n'; //should be "\r\n"
我很确定protocol => mail
不会使用您的提供商 - 它会直接从您的服务器发送电子邮件。
如果不是单引号问题,则可能是凭据不正确,防火墙或连接要求(例如,如果您的电子邮件提供商需要TLS / SSL)。
尝试连接到邮件服务器并发送电子邮件与另一个客户端(您可以使用telnet:http://www.wikihow.com/Send-Email-Using-Telnet或thunderbird或somesuch)来验证协议是否正确。