PHP send mail with SMTP Authentication Print

  • 9

<?php

require_once "Mail.php";

 

$from = "XXXXXX@yourDOMAIN.com";

$to = "XXXXXXX@gmail.com";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

 

$host = "Localhost";

$username = "XXXXXXXX@yourDOMAIN.com";

$password = "XXXXXXXXX";

 

$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>");

 }

?>


Was this answer helpful?

« Back