Welcome Guest, Not a member yet? Register   Sign In
PHPmailer in CI3? [SOLVED]
#1

(This post was last modified: 09-02-2018, 06:57 AM by Gianluigi.)

Hi, as wirte in slack I have trouble to put PHPMailer in CI3.

This code works, but when I call the controller it don't load the view. Mail sent correctly, but page don't load (blank page).

Controller Home.php:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {
   
   function __construct(){
       parent::__construct();
   }
   
public function index()
{
       $this->load->helper('mail');
       if(send_mail('info', '[email protected]', 'Name', 'Object', 'Message <b>bold</b>!'))
       {
           $this->load->view('welcome');
       }

}

Helper mail_helper.php:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

if ( ! function_exists('send_mail'))
{
function send_mail($send_from = NULL, $send_to = NULL, $send_name = NULL, $send_subj = NULL, $send_body = NULL)
{
       include(APPPATH . "helpers/mail_helper/Exception.php");
       include(APPPATH . "helpers/mail_helper/PHPMailer.php");
       include(APPPATH . "helpers/mail_helper/SMTP.php");
       use PHPMailer\PHPMailer\PHPMailer;
       use PHPMailer\PHPMailer\Exception;
       $smtp_host = 'myhost';
       switch ($send_from) {
           case 'info':
               $smtp_user = 'info_user';
               $smtp_pass ='info_pass';
               break;
           case 'others':
               $smtp_user = '';
               $smtp_pass ='';
               break;
       }
       $send_from = $send_from . '@domain.com';
       $mail = new PHPMailer(true);
       $mail->IsSMTP();
       $mail->SMTPOptions = array(
         'ssl' => array(
         'verify_peer' => false,
         'verify_peer_name' => false,
         'allow_self_signed' => true
        )
       );
       $mail->SMTPAuth   = true;
       $mail->Host       = $smtp_host;
       $mail->Port       = 587;
       $mail->SMTPSecure = "tls";
       $mail->Username   = $smtp_user;
       $mail->Password   = $smtp_pass;
       $mail->SMTPDebug  = 0;
       $mail->setFrom($send_from, 'Website Name');
       $mail->addAddress($send_to, $send_name);
       $mail->Subject = $send_subj;
       $mail->Body    = $send_body;
       $mail->IsHTML(true);
       if (!$mail->send()) {
           return true;
       }
       else {
           return false;
       }
}
}

In helpers/mail_helper/ folder there are PHPMailer files included.

If I set $mail->SMTPDebug 1 or 2 instad of 0, page print error: ERR_CONTENT_DECODING_FAILED.

What's wrong with this?
Any help for corrections or to put it as library instead of helper will be great.

Thank you!
Reply


Messages In This Thread
PHPmailer in CI3? [SOLVED] - by Gianluigi - 08-30-2018, 02:53 PM
RE: PHPmailer in CI3? - by Paradinight - 08-30-2018, 08:20 PM
RE: PHPmailer in CI3? - by Gianluigi - 08-31-2018, 01:55 AM
RE: PHPmailer in CI3? - by InsiteFX - 09-01-2018, 04:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB