Codeigniter电子邮件库不在localhost上发送

时间:2013-06-13 17:03:35

标签: php codeigniter email

我知道这已经多了回答,但所有这些答案都没有帮助我解决我的问题。 因为它是最简单的测试方式,所以我使用邮件协议,并在我的本地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"

2 个答案:

答案 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分钟)到inboxspam/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();
    }

尝试这个

相关问题