无法使用CodeIgniter发送电子邮件 [英] Unable to send email with CodeIgniter
问题描述
遇到PHP错误
严重性:警告
消息:fsockopen():无法连接到
ssl://smtp.googlemail.com:465(连接尝试失败,因为
关联方在一段时间后没有正确响应,或
建立连接失败,因为连接的主机失败到
响应。)
文件名:libraries / Email.php
行号:1689
<我有谷歌约三个小时,仍然找不到解决方案。我已经在Apache中启用了' openssl
'。我想描述我的电子邮件控制器类的编码。
//电子邮件控制器索引功能的代码
$这 - >负载>库( '电子邮件');
$ this-> email-> set_newline(\r\\\
);
$ config ['charset'] ='utf-8';
$ config ['wordwrap'] = TRUE;
$ config ['mailtype'] ='html';
$ config ['protocol'] ='smtp';
$ config ['smtp_port'] = 465;
$ config ['smtp_host'] ='ssl://smtp.googlemail.com';
$ config ['smtp_user'] =something@gmail.com;
$ config ['smtp_pass'] =xxx;
$ this-> email-> initialize($ config);
$ this-> email-> from(something@gmail.com','NayLinAung');
$ this-> email-> to(something@gmail.com');
$ this-> email-> subject('This is a email test');
$ this-> email->消息(它正在工作,太好了!你会成功的);
if($ this-> email-> send())
{
echo电子邮件已成功发送。
}
else {
show_error($ this-> email-> print_debugger());
}
当我将smtp更改为邮件时,不会发生错误,电子邮件没有实际发送。另外,我关闭了我的Windows防火墙。
请为此错误提出任何解决方案。
我之前发现的是:
要在CodeIgniter中使用Google SMTP,您需要对您的Gmail帐户设置进行2(2)个更改:(NB请注意攻击者现在更容易入侵您的帐户 - Google)
- 设置两步验证。
- 允许不太安全的应用:ON(或启用)
现在使用'smtp_host'
作为 ssl: //smtp.gmail.com
而不是 smtp.googlemail.com
问题也在此链接中讨论。
希望这个帮助。
I am a novice to CI and PHP. Currently I'm using xammp to run PHP, Apache and MySql. Now I am trying to send an email with CI. But I constantly got an error as below.
A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )
Filename: libraries/Email.php
Line Number: 1689
I have google about three hours and still not found the solution. I have already enabled 'openssl
' in Apache. I would like to describe coding for my Email Controller Class.
//Code of Email Controller 'Index' function
$this->load->library('email');
$this->email->set_newline("\r\n");
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['protocol'] = 'smtp';
$config['smtp_port'] = 465;
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = "something@gmail.com";
$config['smtp_pass'] = "xxx";
$this->email->initialize($config);
$this->email->from('something@gmail.com', 'NayLinAung');
$this->email->to('something@gmail.com');
$this->email->subject('This is an email test');
$this->email->message("It is working, Great! You will be successful.");
if ($this->email->send())
{
echo "Email was successfully sent.";
}
else {
show_error($this->email->print_debugger());
}
When I change 'smtp' to 'mail', errors are not occurred but the email was not actually sent. In addition, I shutdown my Windows firewall.
Please, suggest any solutions for this error.
What I have found earlier is:
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)
Now use 'smtp_host'
as ssl://smtp.gmail.com
instead of smtp.googlemail.com
This issue also discussed in this link.
Hope this help.
这篇关于无法使用CodeIgniter发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!