PHP Mail and Gmail

I used to run my own mail server from my linux machine. Then due to FCC guidelines, comcast blocked the port for the smtp and pop mail, this way i cannot send or receive emails through that linux server.

The other option is enable secure ports for the smtp and the pop and get somebody to redirect that to my server.

So now if i have to send an email from my wordpress based server, i’m going to use the service of google and use that to relay my emails to the users.

What do we need.

First install sSMTP

apt-get install ssmpt

Now open the php.ini, in the /etc/php5/apache2 folder and make sure that the line sendmail_path is uncommented and reads as follows

sendmail_path = /usr/sbin/ssmtp -t

after this you need to restart your webserver.

Now to configure your ssmtp.conf

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

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

# Where will the mail seem to come from?
rewriteDomain=<the website from which the email appears to come from>

# The full hostname
hostname=<the website from which the email appears to come from>

# 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
AuthUser=<the gmail account you are using to relay through>
AuthPass=<gmail password>
UseSTARTTLS=yes
UseTLS=yes
AuthMethod=LOGIN

Now the other config file revaliases

# sSMTP aliases
#
# Format: local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
root::smtp.gmail.com:587
mainuser::smtp.gmail.com:587

Now test your setup from the command line

echo test | sendmail -v -s "testing ssmtp setup" <any_email_id>
Posted in Uncategorized

Comments are closed.