首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CodeIgniter电子邮件库中使用MSMTP

在CodeIgniter电子邮件库中使用MSMTP
EN

Stack Overflow用户
提问于 2016-11-10 05:13:48
回答 2查看 664关注 0票数 12

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

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

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

代码语言:javascript
复制
$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的电子邮件库,因为它有很多我不想自己编写的好功能。

EN

回答 2

Stack Overflow用户

发布于 2016-11-16 05:15:39

我可以毫不费力地通过CodeIgniter和msmtp发送电子邮件。在我的例子中,我使用了Sendgrid,因为我在使用Gmail和Yahoo的msmtp时遇到了认证问题。这是我的设置(运行在Ubuntu14.04,php 5.5.9,Code Igniter latest上):

/home/quickshiftin/.msmtprc 配置- msmtp

代码语言:javascript
复制
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

代码触发器控制器- application/controller/Tools.php

代码语言:javascript
复制
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

代码语言:javascript
复制
$config = [
    'protocol' => 'sendmail',
    'mailpath' => '/usr/bin/msmtp -C /home/quickshiftin/.msmtprc --logfile /var/log/msmtp.log -a sendgrid -t',
];

通过CLI发送电子邮件的

php index.php tools message

对您的问题的思考

您的etc服务器或命令行用户是否可以读取

  • /etc/msmtp/.msmtprc?上述user?
  • popen是否可执行在您的PHP environment
  • Use a debugger中可能被禁用,以便通过调用CI_Email::_send_with_sendmail方法来确定它失败的原因
  • 如果您为msmtp配置了一个日志文件,如我所拥有的,您可以在尝试通过代码触发器发送后查看那里,以捕获潜在的问题
票数 6
EN

Stack Overflow用户

发布于 2016-11-16 03:56:16

我的电子邮件配置如下:

代码语言:javascript
复制
<?php defined('BASEPATH') OR exit('No direct script access allowed.');
// Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['useragent']        = 'PHPMailer';
// 'mail', 'sendmail', or 'smtp'
$config['protocol']         = 'smtp';
$config['mailpath']         = '/project-folder/sendmail';
$config['smtp_host']        = 'smtp.gmail.com';
$config['smtp_user']        = 'Your Gmail Email';
$config['smtp_pass']        = 'Your Gmail Pass';
$config['smtp_port']        = 587;
// (in seconds)
$config['smtp_timeout']     = 30;  
// '' or 'tls' or 'ssl'                     
$config['smtp_crypto']      = 'tls'; 
// PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.                      
$config['smtp_debug']       = 0; 
// Whether to enable TLS encryption automatically if a server supports it, even if `smtp_crypto` is not set to 'tls'.                       
$config['smtp_auto_tls']    = false; 
// SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP.                   
$config['smtp_conn_options'] = array();                 
$config['wordwrap']         = true;
$config['wrapchars']        = 76;
// 'text' or 'html'
$config['mailtype']         = 'html'; 
// 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.                  
$config['charset']          = null;                     
$config['validate']         = true;
// 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all
$config['priority']         = 3;
// "\r\n" or "\n" or "\r"
$config['crlf']             = "\n";
// "\r\n" or "\n" or "\r"                     
$config['newline']          = "\n";                     
$config['bcc_batch_mode']   = false;
$config['bcc_batch_size']   = 200;
// The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.
$config['encoding']         = '8bit';                   
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40516129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档