我正在学习使用gmail发送邮件的教程,但是我得到的是一个只是挂起的页面,甚至没有加载错误。我使用MAMP,这可能是它不工作的原因。通过gmail发送邮件到CodeIgniter
class Email extends CI_Controller{
public function __construct()
{
parent::__construct();
}
function index(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email',
'smtp_pass' => 'pass'
);
$this->load->library('email',$config);
$this->email->set_newline("/r/n");
$this->email->from('email', 'George');
$this->email->to('email');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
if($this->email->send()){
echo 'Your message was sent';
}else{
show_error($this->email->print_debugger());
}
}
}
我没有在我的php.ini这一行,但是你提供的代码似乎工作。我想我需要添加starttls参数。 – Adam
试过这个,它工作。缩小范围,在我的电子邮件配置中添加'$ config ['newline'] =“\ r \ n”'为我解决了这个问题。 –