gpt4 book ai didi

php - Codeigniter 发送谷歌邮件错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:15:08 26 4
gpt4 key购买 nike

我在主机 Cpanel 中使用 Codeignter。在本地我可以通过谷歌帐户发送电子邮件但在主机 Cpanel 上它出错。这是我的配置:

$ci = get_instance();

$ci->load->library('email');

$config['protocol'] = "smtp";

$config['smtp_host'] = "ssl://smtp.gmail.com";

$config['smtp_port'] = 465;

$config['smtp_user'] = "xxx@gmail.com";

$config['smtp_pass'] = "xxx";

$config['charset'] = "utf-8";

$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$ci->email->initialize($config);

在主机上启用 Openssl。

这是错误提示:

.....
Message: fsockopen() ...: unable to connect to ssl://smtp.gmail.com:465
.....

请帮帮我!对不起我的英语不好

最佳答案

#1 确保您在 Apache 中打开或启用了 ssl_module 并在 php.ini 中打开或启用了 allow_url_fopen

#2 确保您在 gmail 设置中启用了 POP3

#3 如果您在启用代理或防火墙的网络中工作;确保您已打开所需的端口 (465)。

试试这个自测代码。

$config['useragent']    = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = '*****developer@gmail.com'; // Your gmail id
$config['smtp_pass'] = '**********'; // Your gmail Password
$config['smtp_port'] = 465;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";

$this->load->library('email');
$this->email->initialize($config);

$this->email->from('trimantradeveloper@gmail.com', 'TSS DEV');
$this->email->to('trimantra@trimantra.com');
$this->email->cc('trimantra@gmail.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();

关于php - Codeigniter 发送谷歌邮件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21199475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com