【问题标题】:Codeigniter sending email not workingCodeigniter 发送电子邮件不起作用
【发布时间】:2015-02-10 09:24:16
【问题描述】:

我正在尝试发送带有一些 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;
    }       

}

截图

【问题讨论】:

  • 看第一张截图,错误看起来像 rcpt to 字段,你确定 email 是正确的?
  • 它现在发送电子邮件,但错误仍然存​​在,在第 75 行,但我看不到该电子邮件的问题,因为电子邮件是正确的,并且详细信息在那里

标签: php html codeigniter email


【解决方案1】:

你从未初始化 $message。第一次去掉“=”前的点:

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

【讨论】:

    猜你喜欢
    • 2017-10-21
    • 2018-09-21
    • 2017-11-30
    • 2014-06-17
    • 2015-04-09
    • 2015-11-03
    • 2018-02-06
    • 1970-01-01
    • 2013-01-07
    相关资源
    最近更新 更多