How to Send Email from a PHP Script Using SMTP Authentication

Install pear:mail, pear:net_smtp

code:
require_once “Mail.php”;

$from = “Sandra Sender “;
$to = “Ramona Recipient “;
$subject = “Hi!”;
$body = “Hi,\n\nHow are you?”;

$host = “mail.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(”

” . $mail->getMessage() . ”

“);
} else {
echo(”

Message successfully sent!

“);
}
?>

Ref: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

This entry was posted in php and tagged . Bookmark the permalink.

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.