PHP mail with SMTP authentication using Pear Mail
by rajesh[ Edit ] 2012-05-08 22:55:03
If you are using php, then you can use php PEAR mail package authenticate.
This needs PEAR Mail installed along with PHP in the server.
Example Code:
<?php
require_once "Mail.php";
$from = "sender@example.com";
$to = "recipient@example.com";
$subject = "Hi";
$body = "Hi, How are you?";
$host = "example.com";
$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);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}