通过Gmail smtp服务器使用Codeigniter发送电子邮件 [英] sending email via gmail smtp server with codeigniter
问题描述
我一直在尝试在codeigniter框架上使用gmail smtp服务器发送电子邮件。
I have been been trying send email by using gmail smtp server on codeigniter framework.
在localhost上进行完美的测试。当我在服务器上对其进行测试时,出现此错误
it working perfect testing on localhost . When I test it on server I got this error
遇到PHP错误
严重性:警告
消息:fsockopen()[function.fsockopen]:无法连接到ssl://smtp.gmail.com:465(连接超时)
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out)
文件名:libraries / Email.php
Filename: libraries/Email.php
行号:1689
我的代码是
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "ticket@gmail.com";
$config['smtp_pass'] = "test123";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('sender@gmail.com', 'Myanmar Bus Ticket');
$list = array('receiver@gmail.com');
$ci->email->to($list);
$ci->email->reply_to('my-email@gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();
非常感谢您的所有帮助
推荐答案
我发现了以下内容:
要在CodeIgniter中使用Google SMTP,您需要对Gmail进行两(两)次更改帐户设置:(注意,请注意,攻击者现在更容易进入您的帐户-Google表示)
To use Google SMTP in CodeIgniter you need to make 2 (two) changes into your Gmail account setting: (N.B. Please be aware that it is now easier for an attacker to break into your account -says Google)
- 设置两步验证。
- 允许安全性较低的应用:打开(或启用)
- Set off 2-step Verification.
- Allow less secure apps: ON (or Enable)
现在使用'smtp_host'
为 ssl://smtp.gmail.com
,而不是 smtp.googlemail.com
希望这对即将到来的访客有帮助。
Hope this will help upcoming visitor.
这篇关于通过Gmail smtp服务器使用Codeigniter发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!