send mail from localhost in php

 

<?php

error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);

set_include_path("." . PATH_SEPARATOR . ($UserDir = dirname($_SERVER['DOCUMENT_ROOT'])) . "/pear/php" . PATH_SEPARATOR . get_include_path());

require_once "Mail.php";

$host = "smtp.gmail.com";

$username = "[email protected]com";

$password = "********";

$port = "587";

$to = "[email protected],[email protected]";

$email_from = "[email protected]com";

$email_subject = "Subject Line Here: " ;

$email_body = "whatever you like Just testing" ;

$email_address = $email_from;




$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);

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

$mail = $smtp->send($to, $headers, $email_body);







if (PEAR::isError($mail)) {

echo("<p>" . $mail->getMessage() . "</p>");

} else {

echo("<p>Message successfully sent!</p>");

}

?>

Leave a Reply

Your email address will not be published. Required fields are marked *