gpt4 book ai didi

php - 将 MSMTP 与 CodeIgniter 电子邮件库结合使用

转载 作者:行者123 更新时间:2023-12-03 01:47:55 26 4
gpt4 key购买 nike

有人在使用 msmtp 时成功地能够使用标准 CodeIgniter 电子邮件库发送电子邮件吗?

我正在运行 Ubuntu,并且已成功安装和配置 MSMTP。我已经能够从命令行发送电子邮件,也可以使用默认的 PHP mail() 函数。

我的 application/config/email.php 文件如下所示

$config = array(
'protocol' => 'sendmail',
'mailpath' => '/usr/bin/msmtp -C /etc/msmtp/.msmtprc -t',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'myemail@gmail.com',
'smtp_pass' => 'xxxxxxxx',
'smtp_port' => 587,
'smtp_timeout' => 30,
'smtp_crypto' => 'tls',
);

但这行不通。如果有人取得了成功,那么很高兴知道您是如何做到的。理想情况下,我想使用 CodeIgniter 的电子邮件库,因为它有很多我不想自己编写的好功能。

最佳答案

我能够通过 CodeIgniter 和 msmtp 发送电子邮件,没有遇到太多麻烦。就我而言,我使用 Sendgrid,因为我在 Gmail 和 Yahoo 中使用 msmtp 时遇到了身份验证问题。这是我的设置(在 Ubuntu 14.04、php 5.5.9、Code Igniter latest 上运行):

msmtp 配置 - /home/quickshiftin/.msmtprc

account sendgrid
host smtp.sendgrid.net
port 587
auth on
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
user SendGridUsername
password SendGridPassword

代码点火器 Controller - application/controller/Tools.php

class Tools extends CI_Controller {

public function message()
{
$this->load->library('email');

$this->email->from('some-dude@gmail.com', 'Nate');
$this->email->to('another-dude@gmail.com');

$this->email->subject('Send email through Code Igniter and msmtp');
$this->email->message('Testing the email class.');

$this->email->send();
}
}

电子邮件库配置 - application/config/email.php

$config = [
'protocol' => 'sendmail',
'mailpath' => '/usr/bin/msmtp -C /home/quickshiftin/.msmtprc --logfile /var/log/msmtp.log -a sendgrid -t',
];

通过 CLI 发送电子邮件

php index.php 工具消息

对您的问题的想法

  • 您的网络服务器或命令行用户可以读取/etc/msmtp/.msmtprc吗? /usr/bin/msmtp 是否可由该用户执行?
  • popen可能在您的 PHP 环境中被禁用
  • 使用a debugger跟踪对 CI_Email::_send_with_sendmail 方法的调用,以确定它在您的案例中失败的原因
  • 如果您像我一样为 msmtp 配置日志文件,您可以在尝试通过 Code Igniter 发送数据后查看该日志文件以捕获潜在问题

关于php - 将 MSMTP 与 CodeIgniter 电子邮件库结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40516129/

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