简体   繁体   中英

Codeigniter smtp in cpanel not working

i'm using cpanel and trying to send emails to multiple emails. i already created email accounts and put the configurations but when i tried sending, there's a lot of errors. i hope someone can help me

?php

 class Notification_model extends CI_Model {

 public function send_notification_email($link){

 $emails = $this->get_all_emails();

 $this->load->helper('email');
 $this->load->library('email');

 $config['protocol']    = 'smtp';
 $config['smtp_host']    = 'lax09.web.com.ph';
 $config['smtp_port']    = '465';
 $config['smtp_auth']    = true;
 $config['smtp_timeout'] = '7';
 $config['smtp_user']    = $this->config->item('admin_email');
 $config['smtp_pass']    = $this->config->item('admin_pass');
 $config['charset']    = 'utf-8';
 $config['newline']    = "\r\n";
 $config['mailtype'] = "html";
 $config['validation'] = TRUE;
 $this->email->initialize($config);


 $this->email->from($this->config->item('admin_email') , 'Sample Sender');
 $this->email->to($emails);
 $this->email->subject('Good day');

 $message = '
       <!DOCTYPE html>
       <html lang="en">';
 $message .= '<p>Hello Everyone,</p>';
 $message .= '<p>We have news for you, just click the link below for details.</p>';
 $message .= '<p><a href="'.$link.'">Click here! </a></p>';
 $message .= '<p>Thank you,</p>';
 $message .= '<p>Sample Sender</p>';
 $message .= '</body></html>';

 $this->email->message($message);
  if ( ! $this->email->send())
         {
           echo "<pre>".$this->email->print_debugger() ."</pre>";
         }
         else{
           return TRUE;
         }
   }

public function get_all_emails(){
  $query = $this->db->get('accounts');
  $emails = array();
  foreach($query->result() as $row){
    $emails[] = $row->email;
  }
  return $emails;
}
  }

here's some of the error

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: errno
Filename: libraries/Email.php
Line Number: 1687

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: errstr
Filename: libraries/Email.php
Line Number: 1688


The following SMTP error was encountered:  
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error: 
Unable to send data: MAIL FROM:
from: 
The following SMTP error was encountered: 
Unable to send data: RCPT TO:
to: 



The following SMTP error was encountered: 
Unable to send email using PHP SMTP.  Your server might not be configured to  send mail using this method.
User-Agent: CodeIgniter
Date: Tue, 9 Feb 2016 14:05:50 +0800
From: "Sample Sender" <project@sample.ph>
Return-Path: <project@sample.ph>
To: aa@gmail.com, bb@g.com, cc@gm.com, dd@yahoo.com, ee@gmail.com, asdsa@g.com, ff@gmail.com
Subject: =?utf-8?Q?Good_day_bamboo_lovers?=
Reply-To: "project@sample.ph" <project@sample.ph>
X-Sender: project@sample.ph
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <56b981be02aa6@sample.ph>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_56b981be02ae7"

This is a multi-part message in MIME format.
Your email application may not support this format.

Try with it

$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE; 
$this->email->initialize($config);

    $this->email->from('FROM email id', 'send email');
    $this->email->to('TO email id');
    $this->email->subject('Subject');
    $this->email->message('message of body');
    $st = $this->email->send();

print_r($this->email->print_debugger());

 public function send_mail($to,$subject,$message){ /* Mail configuration - ONLY USED HERE */ $config = array('protocol' => 'mail', 'wordwrap' => FALSE, 'mailtype' => 'html', 'charset' => 'utf-8', 'crlf' => "\\r\\n", 'newline' => "\\r\\n", 'send_multipart' => FALSE ); $this->load->library('email', $config); $CompanyName = "Domainname"; $setmail = "support@Domainname.com"; $this->email->from( $setmail, $CompanyName ); $this->email->to( $to ); $this->email->subject( $subject ); $this->email->message( $message ); return $this->email->send(); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM