MSMTP.
- Install MSMTP. In Ubuntu you would do the following:
sudo apt-get install msmtp ca-certificates
- Edit the configuration file /etc/msmtprc with the following:
#set defaults
defaults
# Enable or disable TLS/SSL encryption
tls off
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# account settings
account default
host mail.optusnet.com.au # CHANGE THIS!!!
port 25
auth off
from do-not-reply@domain.com.au
logfile /var/log/msmtp/msmtp.log - Edit the configuration of PHP to use MSMTP. Edit the configuration file with the following (in Ubuntu and PHP5, the file is stored in /etc/php5/cli/php.ini
sendmail_path = /usr/bin/msmtp -t
- Create the log file directory and set proper permissions (depends on how your machine is set up:
sudo mkdir /var/log/msmtp
sudo chown [user]:[group] /var/log/msmtp - Tell our system to rotate the logs so that they do not get too large by creating the file /etc/logrotate.d/msmtp:
/var/log/msmtp/*.log {
rotate 12
monthly
compress
missingok
notifempty
} - You can now test it with the following PHP script:
<?php
$to = "your-email@domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
if (mail($to,$subject,$message)) {
echo "Mail Sent.";
} else {
echo "NOT SENT.";
}
Note that in Ubuntu the Apache and CLI have different PHP5 configurations.
ReplyDeleteThis was a MASSIVE source of head-aches for a few hours!!