我知道这已经多了回答,但所有这些答案都没有帮助我解决我的问题。 因为它是最简单的测试方式,所以我使用邮件协议,并在我的本地xampp机器上工作。 这是我的相关代码:
<?php
$this->load->library('email');
$this->email->initialize(array(
'mailtype' => 'html',
'validate' => TRUE
);
$this->email->from($this->config->item('demo@example.org', 'Test');
$this->email->to($email);
$this->email->subject('ServerManager Registration');
$this->email->message($mail_content);
if ($this->email->send()) {
// This becomes triggered when sending
}
?>
变量$ mail_content和$ email拼写正确且有效。
我在xampp环境中启用了mail()日志记录,因此我可以向您显示触发的日志:
mail() on [C:\xampp\htdocs\core\system\libraries\Email.php:1553]: To: ***@live.de -- Headers: User-Agent: CodeIgniter Date: Thu, 13 Jun 2013 18:14:46 +0200 From: "ServerManager" <your@domain.com> Return-Path: <your@domain.com> Reply-To: "your@domain.com" <your@domain.com> X-Sender: your@domain.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <51b9eff6ab7bb@domain.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_51b9eff6ab7c2"
答案 0 :(得分:0)
问题可能是由$this->config->item
的使用引起的。试试这个
$this->load->library('email');
$this->email->initialize(array(
'mailtype' => 'html',
'validate' => TRUE,
));
$this->email->from('demo@example.org', 'Test');
$this->email->to($email);
$this->email->subject('ServerManager Registration');
$this->email->message($mail_content);
if ($this->email->send()) {
// This becomes triggered when sending
echo("Mail Sent");
}else{
echo($this->email->print_debugger()); //Display errors if any
}
P.S你的代码)
在两个地方遗失了
通过向localhost
的 Gmail , Yahoo 和 Rediff邮件帐户发送邮件来检查脚本。邮件以 Gmail (位于spam
文件夹中)提供。至于 Yahoo 和 Rediff邮件,电子邮件尚未发送(已过去15分钟)到inbox
或spam/trash
文件夹
答案 1 :(得分:0)
$this->load->library('email');
public function mail()
{
$config['mailtype'] = 'html';
$this->email->initialize($config);
$data = '';
$email_body = $this->load->view('promo',$data,true);
$this->email->from('demo@example.org', 'Contact request');
$this->email->to('demo.com');
$this->email->subject('Test');
$this->email->message($email_body);
$this->email->send();
echo $this->email->print_debugger();
}
尝试这个