SMTP based Mailing System

This is simple tutorial to send email via SMTP server through PHP Script.

This is usually helpful at shared servers where mail() does not works or is not allowed to send email.

This code can be used on 'Contact Us', 'Feedback', 'Tell a Friend', etc pages.

SMTP is a secured way of sending emails.


define('SMTP_HOST','localhost'); // replace this with your own SMTP server
define('SMTP_USERNAME',''); // SMTP user name
define('SMTP_PASSWORD',''); // SMTP password
define('FROM_MAIL','info@vinayras.com'); // change this 

/* Include mail classes */
 require_once("./mail/Mail.php");

/**
* Email content 
*/
$body = "This is a test Email"; 

$from = FROM_MAIL;
$to = ""; // email address at which email should be sent.
$subject = ""; // Message subject

$host = SMTP_HOST;
$username = SMTP_USERNAME;
$password = SMTP_PASSWORD;

$headers = array ('From' => $from,
	'To' => $to,
	'Subject' => $subject);

	$smtp = Mail::factory('smtp',
	array ('host' => $host,
		'auth' => true,
		'username' => $username,
		'password' => $password));

	$mail = $smtp->send($to, $headers, $body); // Send email now.

For any issues/bug - please email me at vinay@vinayras.com

AttachmentSize
mail.zip83.59 KB
Vinay Yadav at VinayRas Infotech
Vinay Yadav Developer http://www.vinayras.com