2017-07-01 40 views
0

我在笨发送电子邮件在工作循环发送。 什么实际发生的情况是,我receveing的电子邮件,但它行得shwing我已经包含在该消息。以下是脚本:笨 - 收发电子邮件,但没有收到消息,我在电子邮件

<?php 

    Class Email extends CI_Controller 
    { 
     function __construct() 
     { 
      parent::__construct(); 
     } 
     function index() 
     { 

      $config = Array(
       'protocol' => 'smtp', 
       'smtp_host' => 'ssl://smtp.googlemail.com', 
       'smtp_port' => 465, 
       'smtp_user' => 'myemail', 
       'smtp_pass' => 'mypass', 
       'mailtype' => 'html', 
       'charset' => 'iso-8859-1', 
       'send_multipart' => FALSE 
      ); 
      $this->load->library('email', $config); 

      $this->load->database(); 
       $query = $this->db->query('SELECT email FROM users'); 


      // $this->email->initialize($config);  
      // $this->email->set_newline('\r\n'); 



       foreach ($query->result() as $row) 
       { 
         $this->email->clear(); 

         $this->email->set_newline("\r\n"); 
         $this->load->library('email',$config); 




         $this->email->from("mymail","myname"); 


         $this->email->to($row->email); 
         $this->email->subject("THIS IS AN EMAIL TEST"); 
         $this->email->message('Hello, We are <strong>Example Inc.</strong>'); 
         $this->email->set_mailtype("html"); 
         if($this->email->send()) 
         { 
          echo "Your Mail send"; 
         } 
         else 
         { 
          show_error($this->email->print_debugger()); 
         } 
       } 

       echo 'Total Results: ' . $query->num_rows(); 





     } 
    } 

?> 

我期待Hello, We are <strong>Example Inc.</strong>'此消息的电子邮件,但我实际上得到的是

enter image description here

电子邮件没有mesage。我在哪里犯错。

+0

删除'html'标签替换您的代码和检查。 remove' ' –

+0

删除HTML标签不工作。如果我在视图文件夹中传递任何页面模板商店,那么它的工作正常。但是,如果我在消息传递'字符串作为消息()'它不工作。是'send_multipart'是错误的,这是为什么它的发生? –

+0

从foreach循环$内部删除此代码这 - >负载>库(“电子邮件”,$配置);因为你已经装载循环外电子邮件库 –

回答

0

与此

<?php 

    Class Email extends CI_Controller 
    { 
     function __construct() 
     { 
      parent::__construct(); 
     } 
     function index() 
     { 

      $config = Array(
       'protocol' => 'smtp', 
       'smtp_host' => 'ssl://smtp.googlemail.com', 
       'smtp_port' => 465, 
       'smtp_user' => 'myemail', 
       'smtp_pass' => 'mypass', 
       'mailtype' => 'html', 
       'charset' => 'iso-8859-1', 
       'send_multipart' => FALSE 
      ); 
      $this->load->library('email', $config); 

      $this->load->database(); 
       $query = $this->db->query('SELECT email FROM users'); 


      // $this->email->initialize($config);  
      // $this->email->set_newline('\r\n'); 



       foreach ($query->result() as $row) 
       { 
         $this->email->clear(); 

         $this->email->set_newline("\r\n"); 
         $this->load->library('email',$config); 

         $message = '<html><body>'; 
         $message .= 'Hello, We are <strong>Example Inc.</strong>'; 


         $this->email->from("mymail","myname"); 


         $this->email->to($row->email); 
         $this->email->subject("THIS IS AN EMAIL TEST"); 
         $this->email->set_mailtype("html"); 
         $this->email->message($message); 

         if($this->email->send()) 
         { 
          echo "Your Mail send"; 
         } 
         else 
         { 
          show_error($this->email->print_debugger()); 
         } 
       } 

       echo 'Total Results: ' . $query->num_rows(); 





     } 
    } 

?> 
+0

不,它不工作 –

相关问题