消息:mail()[function.mail]:无法连接到“ssl://googlemail.com”端口465的邮件服务器

时间:2013-01-01 02:02:03

标签: php codeigniter

  

//有谁知道我是如何解决这个问题的。我已经在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();  
}

2 个答案:

答案 0 :(得分:2)

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

您需要set the smtp_host preferencesmtp.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());

    }
}