I have installed apache-5.4.2, PHP-5.4.11 and Mysql-5.5.29 . I want to send mail using php. I have realized that I need a SMTP server on my PC in order to send mails. Can anyone please tell me the details on how to install a SMTP server to send mail. Please give me details on it as I am new to this. Just FYI I am using the below code in PHP. Thanks.
<?php
$to = "xyz@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "abc@gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Assuming you have access to a standard email address, then you don’t need an SMTP server on your pc, you simply need to setup your details in the php.ini.
If you open your php.ini file, and find this section;
If you enter in the values supplied for your regular email address (without the square brackets!), Restart your WebServer and PHP, then you should be up and running…
EDIT:
Seems as though GMAIL / Google Apps requires SSL to send email.
As such, there’s a StackOverflow Question here.. How do I Send email using Gmail through mail() ? Where do I put the password?
A full tutorial is here… http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
That has a full tutorial for sending email via gmail and PHPMailer. An excerpt from this is;
1) If you don’t have one, register a GMail account or setup your domain
for Google applications.
2) Download a recent version of PHPMailer (I’m using the version 5.02)
3) Check with your web hosting provider that port 465 (TCP out) is
open, if not ask him to open that port
4) Include the PHPMailer class file:
5) Create those two constant variables to store your GMail login and
password. Use the login for your Google Apps mail account if you
have one.
6) Use the following function to send the e-mail messages (add the
function in one of your included files):
Most of the settings inside the function are required by GMail. While searching for PHPmailer tutorials I found articles with different settings for the port and security. My advice is to use the settings from this tutorial.
7) Call the function within your code:
Use this more “advanced” usage inside your application: