justhrun

ngattach.php

Feb 16th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.     require_once "Mail.php";
  3.     $subject = "Judul/subject email";
  4.     $body = "isi pesan email...";
  5.     $to = "[email protected]";
  6.     $from = "[email protected]";
  7.     $host = "ssl://smtp.gmail.com";
  8.     $port = "465";
  9.     $username = "username_pengirim";
  10.     $password = "password_email";
  11.  
  12.     $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
  13.  
  14.     $namafile = "/nama_path/inidia.pdf";
  15.     $mime = new Mail_mime();
  16.     if ($mime->addAttachment($namafile,'application/pdf')){
  17.         echo "Sukses ngattach pail! </br>";
  18.     } else {
  19.         echo "Duh, gagal coy!</br>";
  20.     }
  21.  
  22.     $smtp = Mail::factory('smtp', array('host' => $host, 'port' => $port,
  23.         'auth' => true, 'username' => $username, 'password' => $password));
  24.  
  25.     $mail = $smtp -> send($to, $headers, $body);
  26.  
  27.     if (PEAR::isError($mail)) {
  28.         echo("<p> Email Gagal dikirim" . $mail -> getMessage() . "</p>");
  29.     }else{
  30.         echo "Email berhasil di kirim ";
  31.     }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment