2016-11-09 50 views
12

使用msmtp時,是否有人能夠使用標準CodeIgniter電子郵件庫成功發送電子郵件?在CodeIgniter電子郵件庫中使用MSMTP

我正在運行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' => '[email protected]', 
    'smtp_pass' => 'xxxxxxxx', 
    'smtp_port' => 587, 
    'smtp_timeout' => 30, 
    'smtp_crypto' => 'tls', 
); 

但是,這是行不通的。如果任何人都成功了,那麼知道你是如何做到這一點很好。理想情況下,我想使用CodeIgniter的電子郵件庫,因爲它具有許多我不想自己編寫的好功能。

+0

使用msmtp而不是CI默認電子郵件庫的目的是什麼。 –

+2

你的意思是什麼「這不起作用」?它錯誤嗎?你得到的錯誤是什麼?通過說你可以通過mail()發送郵件,你的意思是說'mail()轉發到你的msmtp安裝程序? – Narf

+0

http://www.codeigniter。COM/user_guide /庫/ email.html –

回答

-2

我的電子郵件配置低於:

<?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';     
6

我能夠通過笨和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 

代碼點火控制器 - 應用/控制器/ Tools.php

class Tools extends CI_Controller { 

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

     $this->email->from('[email protected]', 'Nate'); 
     $this->email->to('[email protected]'); 

     $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 tools message

思考發送電子郵件

  • /etc/msmtp/.msmtprc您的網絡服務器或命令行用戶可讀?所述用戶可以執行/usr/bin/msmtp嗎?
  • popen可能你的PHP環境
  • 使用a debugger通過呼叫跟蹤到CI_Email::_send_with_sendmail方法被禁用,以確定爲什麼它的失敗,你的情況
  • 如果您配置msmtp在一個日誌文件,因爲我有你可以看看有嘗試通過代碼點火器發送以捕獲潛在問題後
相關問題