【问题标题】:How do i send an array in an email message (CodeIgniter)如何在电子邮件中发送数组(CodeIgniter)
【发布时间】:2013-07-22 13:54:20
【问题描述】:

我想知道如何在电子邮件中发送数组。我正在使用 pre 标签在网页中对其进行格式化。但我无法在电子邮件中发送任何数据。这是我使用的控制器:

  <?php 


    class Notification extends CI_Controller {


    public function index()
        {


            $this->db->select('product_name,project_code'); 
     $this->db->from('user');
     $this->db->like('product_name', 'Test');   



     $array = $this->db->get()->result();
     $size = count($array); 

     echo 'The number of test are: ';
     echo $size;  
       echo '    ';
    echo "<pre>";
     print_r($array);
     echo "</pre>";

     $config = Array(
                  'protocol' => 'smtp',
                  'smtp_host' => 'ssl://smtp.googlemail.com',
                  'smtp_port' => 465,
                  'smtp_user' => 'Email',
                  'smtp_pass' => 'Password',
                  'mailtype'  => 'text', 
                  'charset'   => 'iso-8859-1'
                                  );
                    $this->load->library('email', $config);
                    $this->email->set_newline("\r\n");

                    // Set to, from, message, etc.
                     $this->email->from('sender', 'Name');
            $this->email->to('reciever'); 

            $this->email->subject(' Test Updates');

            $this->email->message($array);



               $result = $this->email->send(); 

    }




}

?>

我想在电子邮件中发送数组 $array,它的格式类似于 pre 标签。 [注意:我已经编辑了电子邮件详细信息。其他电子邮件功能按预期工作]

【问题讨论】:

标签: php codeigniter email


【解决方案1】:

我不认为message 方法将数组作为参数。试试

$this->email->message(print_r($array, true));

【讨论】:

  • 嗨亚伦,感谢您的回复。我尝试了您建议的方法,它确实在电子邮件中发送了数组。关于如何使用类似于“pre”标签的东西来格式化它的任何想法,以便它们可以轻松阅读?
  • 如果您要发送 HTML 电子邮件,请将其括在 &lt;pre&gt; 标记中。否则可能需要遍历数组,形成可读性更强的字符串。
【解决方案2】:

作为您或其他阅读此主题的其他人的替代选择。

您还可以为电子邮件创建一个视图文件,将数组作为数据传递。

在您的控制器中:

$data['my_array'] = $array;
$this->email->message($this->load->view('my_email', $data, TRUE));

在您的 my_email.php 视图中:

<pre><?php print_r($my_array);?></pre>

【讨论】:

  • 非常感谢 thefunker。
【解决方案3】:

您是否定义了电子邮件接收方?喜欢你@gmail.com 确定什么问题你可以使用

echo $this->email->print_debugger();

【讨论】:

    猜你喜欢
    • 2014-01-26
    • 2014-07-13
    • 2013-01-07
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2012-12-16
    • 2015-04-09
    相关资源
    最近更新 更多