簡體   English   中英

無法使用CodeIgniter發送電子郵件

[英]Unable to send email with CodeIgniter

我是CI和PHP的新手。 目前,我正在使用xammp運行PHP,Apache和MySql。 現在,我正在嘗試使用CI發送電子郵件。 但是我經常遇到如下錯誤。

遇到PHP錯誤

嚴重程度:警告

消息:fsockopen():無法連接到ssl://smtp.googlemail.com:465(連接嘗試失敗,因為一段時間后連接方未正確響應,或者連接建立失敗,因為連接的主機無法回應。)

文件名:libraries / Email.php

行號:1689

我有谷歌約三個小時,但仍未找到解決方案。 我已經在Apache中啟用了“ openssl ”。 我想描述我的電子郵件控制器類的編碼。

//電子郵件控制器“索引”功能的代碼

$this->load->library('email');
    $this->email->set_newline("\r\n");

    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['mailtype'] = 'html';
    $config['protocol'] = 'smtp';
    $config['smtp_port'] = 465;
    $config['smtp_host'] = 'ssl://smtp.googlemail.com';
    $config['smtp_user'] = "something@gmail.com";
    $config['smtp_pass'] = "xxx";

    $this->email->initialize($config);

    $this->email->from('something@gmail.com', 'NayLinAung');
    $this->email->to('something@gmail.com');
    $this->email->subject('This is an email test');
    $this->email->message("It is working, Great! You will be successful.");

    if ($this->email->send())
    {
        echo "Email was successfully sent.";
    }
    else {  
        show_error($this->email->print_debugger());
    }

當我將“ smtp”更改為“ mail”時,不會發生錯誤,但實際上並未發送電子郵件。 另外,我關閉了Windows防火牆。

請提出針對此錯誤的任何解決方案。

我之前發現的是:

要在CodeIgniter中使用Google SMTP,您需要對Gmail帳戶設置進行兩(兩)項更改:( 注意,攻擊者現在更容易進入您的帳戶-Google說)

  1. 取消兩步驗證
  2. 允許安全性較低的應用程序 :啟用(或啟用)

現在,將'smtp_host'用作ssl://smtp.gmail.com而不是smtp.googlemail.com

此問題也在此鏈接中討論。

希望能有所幫助。

如果可以對此IMAP庫使用try

Codeigniter Imap庫

你可以用這個代碼連接

$config['protocol'] = "imap";
$config['imap_host'] = 'xxx.xxx.xxx.xxx';
$config['imap_user'] = 'user@domain.com';
$config['imap_pass'] = 'Jk98S**Jlk';
$config['imap_port'] = '993';
$config['imap_mailbox'] = 'INBOX';
$config['imap_path'] = '/imap/ssl/novalidate-cert'; // use this string if you do not want use ssl
$config['imap_server_encoding'] = 'utf-8';
$config['imap_attachemnt_dir'] = './tmp/';
$this->load->library('email', $config);
$this->email->from($frommail);
$this->email->to($tomail);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();

您也可以使用SMTP,但如果允許,我建議您使用IMAP 它具有更多功能,並且比SMTP更新...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM