Codeigniter发送电子邮件不工作

问题描述:

我试图发送电子邮件与一些html数据。我已经有这个功能之一,它工作得很好,唯一的区别是它有一个表,但是当我尝试使用print_r查看表时,它似乎在那里,我不知道问题出在哪里,但它是绝对在消息部分。有人可以帮我出来吗?Codeigniter发送电子邮件不工作

这里的功能

public function send_receipt($ref_number, $fullname){ 
    $this->load->helper('email'); 
    $this->load->library('email'); 

    $config['protocol'] = 'smtp'; 
    $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
    $config['smtp_port'] = '465'; 
    $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('bot_email') , 'Cupcake Paradise'); 
    $this->email->to($this->input->post('email', TRUE)); 
    $this->email->subject('Transaction Receipt'); 

    $message .= ' 
    <!DOCTYPE html> 
    <html lang="en">'; 
    $message .= '<p>Dear '.$fullname.',</p>'; 
    $message .= '<p>Thanks for ordering on Cupcake Paradise. </p>'; 
    $message .= '<p>Please review the orders and pay through bank deposit using the reference number provided </p>'; 
    $message .= '<p> Reference Number: <strong>'.$ref_number.'</strong></p>'; 
    $message .= '<table>'; 
    $message .= '<thead> 
    <tr> 
    <th>Name</th> 
    <th>Quantity</th> 
    <th>Price</th> 
    <th></th> 
    </tr> 
    </thead> 
    <tbody>'; 
    if ($cart = $this->cart->contents()){ 
     foreach ($cart as $item){ 
      $message .='<tr>'; 
      $message .='<td>'.$item['name'].'</td>'; 
      $message .='<td>'.$item['qty'].'</td>'; 
      $message .='<td>'.$item['subtotal'].'</td>'; 
      $message .='</tr>'; 
     } 
    } 
    $message .= '</tbody></table>'; 
    $message .= '<p>Cupcake Paradise Team</p>'; 
    $message .= '</body></html>'; 

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

} 

截图

+0

查看第一张截图,错误看起来像在rcpt字段中,您确定电子邮件是正确的? – GeekRiky 2015-02-10 09:43:32

+0

它现在发送电子邮件,但错误仍然存​​在,在第75行,但我不能看到问题,因为该电子邮件是正确的,细节是在那里 – Alvinrightback 2015-02-10 10:07:40

您从未初始化$消息。第一次在“=”前删除点:

$message = ' 
<!DOCTYPE html> 
<html lang="en">'; 
$message .= '<p>Dear '.$fullname.',</p>';