[英]Unable to send email with CodeIgniter
我是CI和PHP的新手。 目前,我正在使用xammp运行PHP,Apache和MySql。 现在,我正在尝试使用CI发送电子邮件。 但是我经常遇到如下错误。
遇到PHP错误
严重程度:警告
消息:fsockopen():无法连接到ssl://smtp.googlemail.com:465(连接尝试失败,因为一段时间后连接方未正确响应,或者连接建立失败,因为连接的主机无法回应。)
文件名:libraries / Email.php
行号:1689
我有谷歌约三个小时,但仍未找到解决方案。 我已经在Apache中启用了“ openssl
”。 我想描述我的电子邮件控制器类的编码。
//电子邮件控制器“索引”功能的代码
$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());
}
当我将“ smtp”更改为“ mail”时,不会发生错误,但实际上并未发送电子邮件。 另外,我关闭了Windows防火墙。
请提出针对此错误的任何解决方案。
我之前发现的是:
要在CodeIgniter中使用Google SMTP,您需要对Gmail帐户设置进行两(两)项更改:( 注意,攻击者现在更容易进入您的帐户-Google说)
- 取消两步验证 。
- 允许安全性较低的应用程序 :启用(或启用)
现在,将'smtp_host'
用作ssl://smtp.gmail.com
而不是smtp.googlemail.com
此问题也在此链接中讨论。
希望能有所帮助。
如果可以对此IMAP库使用try
你可以用这个代码连接
$config['protocol'] = "imap";
$config['imap_host'] = 'xxx.xxx.xxx.xxx';
$config['imap_user'] = 'user@domain.com';
$config['imap_pass'] = 'Jk98S**Jlk';
$config['imap_port'] = '993';
$config['imap_mailbox'] = 'INBOX';
$config['imap_path'] = '/imap/ssl/novalidate-cert'; // use this string if you do not want use ssl
$config['imap_server_encoding'] = 'utf-8';
$config['imap_attachemnt_dir'] = './tmp/';
$this->load->library('email', $config);
$this->email->from($frommail);
$this->email->to($tomail);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
您也可以使用SMTP,但如果允许,我建议您使用IMAP 。 它具有更多功能,并且比SMTP更新...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.