Codeigniter发送电子邮件不起作用

时间:2015-02-10 09:24:16

标签: php html codeigniter email

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

这里的功能

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;
    }       

}

截图

1 个答案:

答案 0 :(得分:1)

您从未初始化$ message。在&#34; =&#34;之前删除点。第一次:

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