One of the things I find hard in developing a web application is using a library for sending email such as PHPMailer. I find it hard when used to send emails. Another thing I find hard is when sending emails in a localhost webserver. It would also cost me more and would take much time in setting up my own mail server. PHP’s mail function is also very useless in such testing ground.
If you are using a gmail account and want to use PHP’s mail function in your local webserver, here is a better way to relay an email to gmail. I am using backtrack 5 Gnome and the steps will also work for debian based distros. Follow the steps below,
After installing ssmtp, open the configuration file.
Below is an example configuration to have it working, compare your existing configuration to what I have below and apply the changes
# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
# Where will the mail seem to come from?
# The full hostname
# 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
After the changes, you can now use PHP’s mail function
$message = "This is a test";
$message = wordwrap($message, 70);
mail('[email protected]', 'My Subject', $message);