我正在尝试使用PHP CodeIgniter框架发送电子邮件。在我将该文件上传到我的浏览器后,它没有显示任何错误。它说:“您的电子邮件已成功发送”。但是我的电子邮件帐户中没有收到任何电子邮件。我无法弄清楚问题是什么。我正在使用CodeIgniter版本2.1.3。谁能帮帮我吗。我是PHP新手。谢谢。这是我的代码:
<?php
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('email');
$this->email->from('[email protected]', 'Hasan Hasibul');
$this->email->to('[email protected]');
$this->email->subject('email test');
$this->email->message('testing the email class. email sent');
if($this->email->send()){
echo"Your email was sent successfully";
}else
{
show_error($this->email->print_debugger());
}
}
}
你可以试试这个:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => '....',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$email_setting = array('mailtype'=>'html');
$this->email->initialize($email_setting);
$email_body ="<div>hello world</div>";
$this->email->from('[email protected]', 'shahriar');
$list = array('[email protected]');
$this->email->to($list);
$this->email->subject('Testing Email');
$this->email->message($email_body);
$this->email->send();
echo $this->email->print_debugger();
}
这对我有用。快乐的编码:)
这是因为您的localhost中没有邮件服务器设置。您可以设置它,也可以使用您的Gmail帐户发送您的邮件,如下所示 -
$config = Array(
‘protocol’ => ‘smtp’,
‘smtp_host’ => ‘ssl://smtp.googlemail.com’,
‘smtp_port’ => 465,
‘smtp_user’ => ‘[email protected]’,
‘smtp_pass’ => ‘mypassword’,
);
$this->load->library('email', $config);
$this->email->from('[email protected]', 'Hasan Hasibul');
$this->email->to('[email protected]');
$this->email->subject('email test');
$this->email->message('testing the email class. email sent');
if($this->email->send()){
echo"Your email was sent successfully";
} else {
show_error($this->email->print_debugger());
}
检查邮件队列中的电子邮件服务器。可能在等