Tuesday, 14 February 2017

Send Mail By Using SMTP Authentication in Php.

<?php
 require_once "Sendmail.php";

 $from = "Sender <sender@abc.com>";
 $to = "Recipient <recipient@abc.com>";
 $subject = "Hi!";
 $body = "Hello";

 $host = "mail.abc.com";
 $uname = "smtp_uname";
 $pass = "smtp_pass";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'author' => true,
     'uname' => $uname,
     'pass' => $pass));

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

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Your Mail Successfully Sent!</p>");
  }
 ?>

0 comments:

Post a Comment