Advertisement
Guest User

Untitled

a guest
Apr 1st, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2. if (!defined('BASEPATH')) exit('No direct script access allowed');
  3.  
  4. class Login extends MX_Controller
  5. {
  6.  
  7.     function __construct(){
  8.         parent::__construct();
  9.  
  10.         $this->load->database();
  11.     }
  12.  
  13.     function doforgetpass() {
  14.         $from       = 'from_mail@gmail.com';
  15.         $to         = 'to_mail@gmail.com';
  16.         $subject    = 'Test Mail';
  17.         $message    = 'Mail content as Plaintext or HTML';
  18.  
  19.         var_dump( $this->send_mail( $from, $to, $subject, $message ) );
  20.         exit;
  21.     }
  22.  
  23.     function send_mail($from = null, $to = null, $subject = null, $message = null, $attachment = null) {
  24.         $isReady = false;
  25.  
  26.         // Config SMTP
  27.         $config = Array(
  28.             'protocol'  => 'smtp',
  29.             'smtp_host' => 'ssl://smtp.googlemail.com',
  30.             'smtp_port' => 465,
  31.             'mailtype'  => 'html',
  32.             'smtp_user' => 'emai@gmail.com', // Email
  33.             'smtp_pass' => 'password_email' // Email Password
  34.         );
  35.         $this->load->library('email', $config);
  36.  
  37.         // Validate Params
  38.         if ( !is_null($from) && !is_null($to) && !is_null($subject) && !is_null($message) ) {
  39.             // Set Content
  40.             $this->email->from( $from, 'Mail Sender Name' );
  41.             $this->email->to( $to );
  42.             $this->email->subject( $subject );
  43.             $this->email->message( $message );
  44.            
  45.             $isReady = true;
  46.  
  47.             if ( !is_null($attachment) ) {
  48.                 if ( is_array($attachment) ) {
  49.                     // Set Attachment
  50.                     foreach ( $attachment as $key => $item ) {
  51.                         $this->email->attach( $item );
  52.                     };
  53.    
  54.                     $isReady = true;
  55.                 } else {
  56.                     $isReady = false;
  57.                 };
  58.             };
  59.         };
  60.        
  61.         // Send Mail
  62.         if ( $isReady == true ) {
  63.             return $this->email->send();
  64.         } else {
  65.             return array('status' => false, 'error' => 'Invalid params.');
  66.         };
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement