Monday, September 20, 2010

Configure LAMP on Ubuntu 10.04 to send email via PHP mail function

edited 2010-11-08 former guide doesn't work for me more (changed to ubuntu 10.10 64b lampp  1.7.3a) but this helped me http://tombuntu.com/index.php/2008/10/21/sending-email-from-your-system-with-ssmtp/

---- OLD ----
Lampp comes like standalone package without need to reconfigure something. It runs out of box. But If your Ubuntu installation has no configured mail server, it is problem to send mails via PHP mail function. Here is quick solution how use Gmail SMTP server to send emails from localhost:

sudo apt-get install ssmtp

sudo gedit /etc/ssmtp/ssmtp.conf
edit variables hostname, FromLineOverride
hostname=smtp.gmail.com
FromLineOverride=YES

sudo gedit /opt/lampp/etc/php.ini
add or change following variables in php.ini
smtp_port = 465
sendmail_path =/usr/sbin/ssmtp -t

Restart lampp
sudo /opt/lampp/lampp restart

create php mail testing script like:

$additional_headers = 'From: michaeljackson@heaven.org' . "\r\n";
$res = mail('recipient@domain.com','test','test body', $additional_headers);
var_dump($res);
?>


$res should be TRUE after executing and check out your mail mailbox, there should be something like this:

Thanks to this forum post.

5 comments:

Anonymous said...

Great! In my case php.ini was located in /etc/php5/apache2/php.ini

Thanks a lot!

Anonymous said...

Great! In my case php.ini was located in /etc/php5/apache2/php.ini

Thanks a lot!

IreneLing said...

Hello thanks for this useful tutorial,it works.
But the email I received will put "nobody" as the sender name even I already add the "From:" in headers.
What can I do to change it?

IreneLing said...

Problem solved...I just noticed that I didn't change FromLineOverride=YES...
Still thanks to your tutorial,really help me a lot.

Anonymous said...

I have done same as per instruction...

but o/p is bool(false) ...

I am using LAMP in UBUNTU 12.04

any new idea please?