2016-11-09 3 views
12

Может ли кто-нибудь успешно отправлять электронную почту, используя стандартную библиотеку электронной почты CodeIgniter при использовании msmtp?Использование 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' => '[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.ком/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

я был в состоянии послать по электронной почте через CodeIgniter и msmtp без особых проблем. В моем случае я использовал Sendgrid, когда сталкивался с проблемами аутентификации, используя msmtp с Gmail и Yahoo. Вот мои настройки (работает на 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(); 
    } 
} 

Email Library Config - приложение/Config/email.php

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

Отправка по электронной почте

php index.php tools message

Мысли о вашей проблеме с помощью CLI

  • /etc/msmtp/.msmtprc читается вашим веб-сервером или пользователем командной строки? Есть /usr/bin/msmtp исполняемый пользователем?
  • popen может быть отключена в вашем PHP среде
  • Использование a debugger проследить через призыв к CI_Email::_send_with_sendmail метод, чтобы определить, почему он терпит неудачу в вашем случае
  • Если настроить файл журнала для msmtp, как у меня есть вы можете посмотреть здесь после попытки отправки через заголовок кода, чтобы поймать потенциальные проблемы
Смежные вопросы