0

//有谁知道我是如何解决这个问题的。我已经在 php.ini 上取消了必要的文件的注释但无济于事我仍然得到错误,我使用 xampp 作为我的本地主机。

//emails.php
function email(){
    $this->load->model('user');
    $emails=$this->user->get_emails();
    $this->load->library('email');
    $config['mailtype']='html';
    $this->email->initialize($config);
    foreach($emails as $row){
        $email_config = Array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => '465',
        'smtp_user' => 'dirk@gmail.com',
        'smtp_pass' => 'dirk',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
    );
    $this->load->library('email', $email_config);

        if($row['email']){
            $this->email->from('dirk@gmail.com', 'dirk');
            $this->email->to($row['email']);
            $this->email->subject('Test Newsletter');
            $this->email->message('Your email message goes here! <strong>Bold</strong>');
            $this->email->send();
            $this->email->clear();
        }
    }
}
//user.php
function get_emails(){
    $this->db->select('email')->from('users');
    $query = $this->db->get();
    return $query->result_array();  
}
4

2 回答 2

2

GMail 不googlemail.com用于 smtp,SMTP 服务器smtp.gmail.com希望对您有所帮助。

您需要将 smtp_host 首选项设置smtp.gmail.com.

于 2013-01-01T02:05:16.293 回答
0

输入有效的 gmail 电子邮件而不是abc@gmail.comatsmtp_user并填写密码。$from还要在数组和数组中放入有效的电子邮件$to

  $emailConfig = array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'abc@gmail.com',
        'smtp_pass' => '*******',
        'mailtype' => 'html', //text or html
        'charset' => 'iso-8859-1',
    );
     $from = array('email' => 'abc@gmail.com');
    $to = array('abc@gmail.com');
    $subject = "Testing Mail";
    $message = "Welcome";
    $this->load->library('email', $emailConfig);
    $this->email->initialize($emailConfig);

    $this->email->set_newline("\r\n");
    $this->email->from($from['email']);
    $this->email->to($to);
    $this->email->subject($subject);
    $this->email->message($message);

    if ($this->email->send()) {
     echo "success";
          } else {

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

    }
}
于 2013-01-01T10:00:12.797 回答