To use smtp to send mail with php

Problems with the Linux version of XAMPP, questions, comments, and anything related.

To use smtp to send mail with php

Postby popscript » 29. November 2009 22:50

To use smtp to send mail with php

After spending 3 days trying to get my Ubuntu server to send mail using PHP scripts on my server I finally got it working and wanted to post here how it was done. Hopefully I can save others out there how to get this done without spending so much time.

First off this tutorial is for comcast customers trying to get there ubuntu server to send mail out on their servers using PHP scripts.
Comcast has officially blocked port 25 many years ago so we will use their alt port 587

This specific tutorial is for those that run apache under xampp for linux.

First install ssmtp;

Open terminal and type;

apt-get install ssmtp

Or if you are not logged in as root
sudo apt-get install ssmtp

Next, configure ssmtp with login info for comcast:

SSMTP Config file:

Your ssmpt.conf file should look like this:

First open the ssmtp.conf file by using the terminal command below.

gedit /etc/ssmtp/ssmtp.conf

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com or smtp.comcast.net:587
mailhub=smtp.comcast.net:587

AuthUser=yourcomcastemail@comcast.net
AuthPass=yourpasswordhere
UseSTARTTLS=yes
UseTLS=yes

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
#hostname=smtp.comcast.net

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES



Change php.ini file for apache: (Applies if you have installed xampp for linux)
Your Apache server will not know where to look for the ssmtp server unless you show it where the path is located at to send mail in your php.ini file.

/opt/lampp/etc/php.ini

find line:
sendmail_path = /usr/sbin/ssmtp -t
NOTE: The -t is required by Apache in order to allow PHP to send mail.

This tells apache how to send mail using php scripts on your ubuntu server.

The most important: restart apache

/opt/lampp/lampp restart

If would like, you can test email by opening terminal and use this command;
echo "This is a test message. Ubuntu rocks!" | mailx -s 'Testing This Email SMTP Server' anyemail@anydomain.com

The End:
You should now be able to send mail from your PHP scripts on your ubuntu apache server without having to specify the login for comcast for each and every script hosted on your server.

IMPORTANT NOTES:
1) If you put an email address into the line; root= the server will send mail however it will show it coming from your actual comcast email address. This might not be good for the other professional domains that you maybe hosting on your ubuntu server. If you allow override as posted above and leave the root= empty then the email will appear to come from the domain it was sent from.
2) Due to the fact that ssmtp uses login you may also be able to use gmail to send mail through their smtp servers however this was not tested in this tutorial although it should work as well.
popscript
 
Posts: 1
Joined: 29. November 2009 22:46

Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 16 guests