【问题标题】:Message: mail() [function.mail]: Failed to connect to mailserver at "ssl://googlemail.com" port 465消息:mail() [function.mail]:无法在“ssl://googlemail.com”端口 465 连接到邮件服务器
【发布时间】:2023-03-11 09:38:01
【问题描述】:

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

【问题讨论】:

标签: php codeigniter


【解决方案1】:

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

您需要将set the smtp_host preference 转至smtp.gmail.com

【讨论】:

  • 那么我在哪里配置我的 smtp 服务器?
【解决方案2】:

smtp_user 输入有效的gmail 电子邮件而不是abc@gmail.com 并填写密码。还要在$fromarray 和$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());

    }
}

【讨论】:

    猜你喜欢
    • 2011-01-21
    • 2011-10-24
    • 1970-01-01
    • 2017-03-08
    • 2012-08-02
    • 2014-05-15
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多