现在几个月来,我一直在试图找出如何解决此错误的方法,我在Google上进行了搜索,并在此处检查解决方案,但是老实说,我越看越少。
该代码应该执行什么操作,以从数据库表中收集消息列表,然后遍历它们并分别邮寄电子邮件地址。
这是代码
应用程序/库/Send_email.php
<?php
class Send_email{
public $CI;
public function __construct(){
$this->CI =& get_instance();
}
public function msg_user_now(){
$CI ='';
$this->CI =& get_instance();
$list_mess =$this->CI->Action->get_message_2();
if(is_array($list_mess)){
foreach($list_mess as $row){
$mess_id =$row['mess_id'];
$mess_sender =$row['mess_sender'];
$mess_reciever =$row['mess_reciever'];
$mess_topic =$row['mess_topic'];
$mess_body =$row['mess_body'];
$reciever_email =$this->CI->Action->get_email_by_username($mess_reciever);
$site_name =$this->CI->Action->get_site_name();
$site_g_name =$this->CI->Action->get_site_g_name();
$site_g_pass =$this->CI->Action->get_site_g_pass();
$data['site_name'] =$site_name;
/*======================================SEND EMAIL TO USER When Notify ==================================*/
$config =array(
'protocol'=> 'ssmtp',
'smtp_host' => 'ssl://ssmtp.gmail.com',
'smtp_port' => '465',
'smtp_timeout' => '7',
'smtp_user' => $site_g_name,
'smtp_pass' => $site_g_pass,
'charset' => 'utf-8',
'newline' => "\r\n",
'mailtype' => 'text', // or html
'validation' => FALSE); // bool whether to validate email or not
$this->CI->load->library('email');
$this->CI->email->clear();
$this->CI->load->initialize($config);
$this->CI->email->set_mailtype("html");
$this->CI->email->from('info@sitename.com', 'siteAdmin');
$this->CI->email->to($reciever_email);
$this->CI->email->subject($mess_topic);
$link =base_url().'Login/login_user';
$data['link'] =$link;
$data['link_title'] ='Login To See More Detail';
$data['message'] =$mess_body;
$data['message_title'] =$mess_topic;
$body =$this->CI->load->view($this->CI->email_layout_2,$data,TRUE);
$this->CI->email->message($body);
if($this->CI->email->send()){
$this->CI->Action->update_message_list($mess_reciever);
}
//else{
// //return FALSE;
// $this->CI->Action->update_message_list($mess_reciever);
// }
//echo $this->email->print_debugger();
/*======================================End SEND EMAIL TO USER When MATCHED==================================*/
}
}
}
}
Application / Model / Action.php
public function get_message_2(){
$this->db->where('email_alert', 'Yes');
$query = $this->db->get('message');
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return false;
}
}
Application / Controller / Cron_ctrl.php
<?php
class Cron_ctrl extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->library('Send_email');
}
public function perform_cron_msg(){
$this->send_email->msg_user_now();
}
}
这是Cron Job Command
php -q /home/esukuxyz/ecard9ja.com/index.php Cron_ctrl perform_cron_msg
这是我收到的电子邮件中的结果
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: session_start(): Cannot send session cookie - headers already sent</p>
<p>Filename: Session/Session.php</p>
<p>Line Number: 143</p>
<p>Backtrace:</p>
<p style="margin-left:10px">
File: /home/esukuxyz/site_name.com/application/core/My_Controller.php<br />
Line: 10<br />
Function: __construct </p>
<p style="margin-left:10px">
File: /home/esukuxyz/site_name.com/application/controllers/Welcome.php<br />
Line: 5<br />
Function: __construct </p>
<p style="margin-left:10px">
File: /home/esukuxyz/site_name.com/index.php<br />
Line: 315<br />
Function: require_once </p>
</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: session_start(): Cannot send session cache limiter - headers already sent</p>
<p>Filename: Session/Session.php</p>
<p>Line Number: 143</p>
<p>Backtrace:</p>
<p style="margin-left:10px">
File: /home/esukuxyz/site_name.com/application/core/My_Controller.php<br />
Line: 10<br />
Function: __construct </p>
<p style="margin-left:10px">
File: /home/esukuxyz/site_name.com/application/controllers/Welcome.php<br />
Line: 5<br />
Function: __construct </p>
<p style="margin-left:10px">
File: /home/esukuxyz/site_name.com/index.php<br />
Line: 315<br />
Function: require_once </p>