我正在尝试设置一个联系表单,但我正在努力让它与 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);
$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;
我刚刚问了我的托管服务提供商,所有SMTP配置都是正确的。他们还检查了我的电子邮件帐户是否正常工作。
事实上,如果我选择:
协议 => "邮件"
消息传递没有问题。AFAIK php mail() 函数也使用托管提供程序 SMTP,但它只是将其交给服务器并忘记它。
相反,我想使用SMTP身份验证,这担心电子邮件的发送。但只有通过改变
协议 => "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: <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...
此错误的原因可能是什么?
有些人报告说,配置项带有单引号
时出现问题:$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 或类似的东西)来验证协议是否正确。