I want to send an email in php from my localhost which includes mail.php file.
Here is my code for test.php file:
<?php
include_once("Mail.php");
$From = "Sender's name <testing123xyz@gmail.com>";
$To = "Recipient's name <test2@gmail.com>";
$Subject = "Send Email using SMTP authentication";
$Message = "This example demonstrates how you can send email with PHP using SMTP authentication";
$Host = "mail.gmail.com";
$Username = "testing123xyz";
$Password = "testing";
// Do not change bellow
$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, $Message);
if (PEAR::isError($mail)){
echo($mail->getMessage());
} else {
echo("Email Message sent!");
}
?>
When i hit the url of test.php file, server is throwing following error :
Failed to connect to smtp.gmail.com:25 [SMTP: Failed to connect socket: No connection could be made because the target machine actively refused it. (code: -1, response: )]
Please help me out. Thanks.