//有谁知道我是如何解决这个问题的。我已经在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();
}
答案 0 :(得分:2)
GMail不会将googlemail.com
用于smtp,SMTP服务器smtp.gmail.com
希望有所帮助。
您需要set the smtp_host preference到smtp.gmail.com
。
答案 1 :(得分:0)
在abc@gmail.com
放置有效的Gmail电子邮件而不是smtp_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());
}
}