通过gmail在CodeIgniter中发送电子邮件
问题描述:
我按照一个教程使用gmail发送电子邮件,但我得到的是一个刚刚挂起,甚至不加载错误的页面。我使用MAMP,这可能是它不工作的原因。
I'm following a tutorial to send emails using gmail, however what I get is a page that just hangs and doesn't even load an error. I'm using MAMP so that may be a reason why it isnt working.
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文件中取消注释extension = php_openssl.dll
in your php.ini file uncomment extension=php_openssl.dll
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser@gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', config);
$this->email->from('email@gmail.com', 'George');
$this->email->to('email@gmail.com');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
$this->email->send();
echo $this->email->print_debugger();
希望这会奏效