script php untuk kirim mail via smtp auth TLS

web server harus mendukung pear Mail. untuk petunjuk umum instalasi paket pear klik disini.

$ pear channel-update pear.php.net
$ pear install Net_SMTP
$ pear install Mail

contoh script php untuk kirim email:

<?php
 require_once "Mail.php";

 $from = "gregor <gregor@mail.com>";
 $to = "kawan <kawan@mail.com>";
 $subject = "kirim via php mail";
 $body = "Halo,nn ini coba kirim dari php";

 $host = "ip.smtp.server.nya";
 $port = "587";
 $username = "user-yg-valid@smtp-server";
 $password = "passwordnya";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     '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>");
  }
 ?>

Latest posts by gregor (see all)

Leave a Reply

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


*