Has anyone successfully been able to send email using the standard CodeIgniter email library when using msmtp?
I'm running Ubuntu and I've successfully installed and configured MSMTP. I've been able to send email from the command line and also using the default PHP mail()
function.
My application/config/email.php
file looks like this
$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',
);
But this doesn't work. If anyone's been successful it would be good to know how you did it. Ideally I'd like to use CodeIgniter's email library as it has a lot of good functionality that I don't want to have to write myself.
Simply create a new file called the email. php, add the $config array in that file. Then save the file at config/email. php and it will be used automatically.
I was able to send an email through CodeIgniter and msmtp without too much trouble. In my case I used Sendgrid as I encountered authentication issues using msmtp with Gmail and Yahoo. Here's my setup (running on Ubuntu 14.04, php 5.5.9, Code Igniter latest):
msmtp config - /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
Code Igniter Controller - application/controller/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 - application/config/email.php
$config = [
'protocol' => 'sendmail',
'mailpath' => '/usr/bin/msmtp -C /home/quickshiftin/.msmtprc --logfile /var/log/msmtp.log -a sendgrid -t',
];
Sending the email via the CLI
php index.php tools message
Thoughts on your issue
/usr/bin/msmtp
executable by said user?popen
may be disabled in your PHP environmentCI_Email::_send_with_sendmail
method to determine why it's failing in your caseIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With