php - CodeIgniter 无法在 VPS 上发送电子邮件
问题描述
我目前正在使用 CodeIgniter 开发 REST API。我得到了一个使用 gmail smtp 的电子邮件验证系统,在 localhost 上工作得很好。但是当我将它上传到 VPS 服务器时,它不起作用。
这是我的代码:
protected function send_confirmation($email, $hash){
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'utf-8',
'crlf' => "\r\n",
'newline' => "\r\n"
);
$this->load->library('email', $config);
$mail = $this->email;
$mail->from('no-reply@example.com', 'Example.com');
$mail->to($email);
$mail->subject('Email Verification');
$encodemail = urlencode($email);
$message = 'Some messages here.';
$mail->message($message);
$mail->send();
}
另请注意,我使用的是PHP 7.2,并且尝试了许多配置,但在 VPS 服务器上似乎没有任何效果。
解决方案
试试这些
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com', #changed
'smtp_port' => 587, #changed
'smtp_user' => 'xxx@gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n"
);
或使用PHPMailer
推荐阅读
- c++ - 为什么带有接受实际变量的指针参数的函数?
- javascript - 一个与标签一起位于 div 中的单选按钮应根据三个不同的按钮单击来更改三种颜色
- flutter - 在颤动一段时间后更改文本的颜色部分
- html - 排列 flexbox 元素,第一个子元素占据整个两行高度
- elasticsearch - 在 Elasticsearch 中将关键字/字符串转换为整数字段
- python - Tensorflow:ValueError:没有为任何变量提供梯度
- python - 如何使用 Python 在 Linux 的非活动窗口中模拟击键和鼠标点击?
- c - “if (isupper(argument) == true)”和“if (isupper(argument))”有什么区别?注意:参数是我程序中的任何字符
- python - 在 matplotlib (pandas) X 和 Y 轴规格中绘制直方图
- javascript - 为什么我的联系页面上的登录按钮无法使用?