Home > other >  Issues with email deliverability with CodeIgniter. my code returns email sent, but doesn't get
Issues with email deliverability with CodeIgniter. my code returns email sent, but doesn't get

Time:01-11

Here's my code. I have tried using 'mail' as protocol, yet still doesn't deliver. But it does get delivered on localhost perfectly and on other servers. But on this particular vps server, it doesn't. Thanks in advance.

$config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => '[email protected]',
        'smtp_pass' => '***********',
        'smtp_timeout' => 10,
        'mailtype' => 'html',
        'starttls'  => true,
        'newline'   => "\r\n", 
    );
    $this->load->library('email');
    $this->email->initialize($config);
    $this->email->from($sender);
    $this->email->to($email);
    $this->email->subject($subject);
    $this->email->message($mailToSend);
    $flag = $this->email->send();
    if ($flag) {
        return $flag;
    } else {
        return false;
    }

CodePudding user response:

Remove the

$this->email->initialize($config);

line and let Codeigniter to use it's default parameters. Or use this configs

$config['useragent']        = 'PHPMailer';              
$config['protocol']         = 'mail';                   
$config['mailpath']         = '/usr/sbin/sendmail';
$config['smtp_host']        = 'localhost';
$config['smtp_user']        = '';
$config['smtp_pass']        = '';
$config['smtp_port']        = 25;
$config['smtp_timeout']     = 30;                       
$config['smtp_crypto']      = '';                       
$config['smtp_debug']       = 0;                        
$config['smtp_auto_tls']    = true;                     
$config['smtp_conn_options'] = array();                 
$config['wordwrap']         = true;
$config['wrapchars']        = 76;
$config['mailtype']         = 'html';                   
$config['charset']          = null;                     
$config['validate']         = true;
$config['priority']         = 3;                        
$config['crlf']             = "\n";                     
$config['newline']          = "\n";                     
$config['bcc_batch_mode']   = false;
$config['bcc_batch_size']   = 200;
$config['encoding']         = '8bit'; 

$this->email->initialize($config);

CodePudding user response:

I got this and it seems to send mail, but the issue with this is it doesn't send to the recipient. Instead, it sends it to the webMail.

$this->load->library('email');
        $config['mailtype'] = 'html';
        $config['protocol'] = 'sendmail';  
        $config['smtp_port'] = '465'; 
        $config['mailpath'] = '/usr/sbin/sendmail';
        $this->email->initialize($config);
        
        
        $this->email->message($mailToSend);
        $this->email->subject($subject);
        $this->email->from($sender);
        $this->email->reply_to("[email protected]");
        $this->email->to($email);
        
       
        // Set recipients
        $this->email->bcc_batch_mode = true;
        $this->email->bcc_batch_size = 50;
        $this->email->bcc("[email protected]);
         
        set_time_limit(0);
        ignore_user_abort(true);
        
        // Send this mailing
        $flag = $this->email->send();
        if ($flag) {
            return $flag;
        } else {
            return false;
        }
  •  Tags:  
  • Related