【问题标题】:Codeigniter - Receiving Email but not receiving message which I send in EmailCodeigniter - 接收电子邮件但未收到我在电子邮件中发送的消息
【发布时间】:2017-12-05 01:21:28
【问题描述】:

我正在努力在 codeigniter 中循环发送电子邮件。 实际发生的事情是我正在收到电子邮件,但它没有显示我包含的消息。以下是脚本:

    <?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 &lt;strong&gt;Example Inc.&lt;/strong&gt;' 电子邮件中的这条消息,但我实际得到的是

电子邮件中没有消息。我哪里出错了。

【问题讨论】:

  • 删除html标签并检查。删除&lt;strong&gt;&lt;/strong&gt;
  • 删除 html 标签不起作用。如果我在视图文件夹中传递任何页面模板存储,那么它工作正常。但是,如果我在message() 中将字符串作为消息传递,则它不起作用。 send_multipart 是假的,这就是它发生的原因?
  • 从 foreach 循环中移除这段代码 $this->load->library('email',$config);因为您已经在循环之外加载电子邮件库

标签: codeigniter email codeigniter-2


【解决方案1】:

用这个替换你的代码

<?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();





        }
    }

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 2014-07-20
    • 1970-01-01
    • 2022-10-22
    相关资源
    最近更新 更多