Advertisement
cahyadyazin

mail codeigniter 2

Oct 23rd, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.     class Mail2 extends CI_Controller {
  3.         public function __construct() {
  4.             parent::__construct();
  5.        
  6.         require_once(APPPATH.'libraries/PHPMailerAutoload.php');
  7.         require_once(APPPATH.'libraries/class.phpmailer.php');
  8.         require_once(APPPATH.'libraries/class.smtp.php');
  9.     }
  10.     public function index() {
  11.         $mail = new PHPMailer();
  12.         $mail->IsSMTP(); // we are going to use SMTP
  13.         $mail->SMTPAuth   = true; // enabled SMTP authentication
  14.         $mail->SMTPSecure = "ssl";  // prefix for secure protocol to connect to the server
  15.         $mail->Host       = "smtp.gmail.com";      // setting GMail as our SMTP server
  16.         $mail->Port       = 465;                   // SMTP port to connect to GMail
  17.         $mail->Username   = "dyazincahya.cd@gmail.com";  // user email address
  18.         $mail->Password   = "***";            // password in GMail
  19.         $mail->SetFrom('dyazincahya.cd@gmail.com', 'DYAZ OX');  //Who is sending the email
  20.         $mail->AddReplyTo("dyazincahya@gmail.com","Cahya Dy");  //email address that receives the response
  21.         $mail->Subject    = "tester mail";
  22.         $mail->Body      = "<h1>Hallo</h1>";
  23.         $mail->AltBody    = "coba coba";
  24.         $destino = "cobamasuk80@gmail.com"; // Who is addressed the email to
  25.         $mail->AddAddress($destino, "hanny");
  26.  
  27.         $mail->AddAttachment("");      // some attached files
  28.         $mail->AddAttachment(""); // as many as you want
  29.         if(!$mail->Send()) {
  30.             $data["message"] = "Error: " . $mail->ErrorInfo;
  31.         } else {
  32.             $data["message"] = "Message sent correctly!";
  33.         }
  34.         $this->load->view('sent_mail.php',$data);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement