2

我正在为我的 android 应用程序开发网络服务,但我的电子邮件功能很难正常工作。我按照本教程在这里

在我的控制器中我有这个:

function forgotPassword_get(){
        $this->load->model('model');
        
        $this->response->format = 'json';
        
        $email = $this->get('email');
    
    $config['protocol'] = 'sendmail';
    $config['mailpath'] = '/usr/sbin/sendmail';
    $config['charset'] = 'iso-8859-1';

    // gmail specific settings here
    $config['smtp_host'] = 'smtp.gmail.com';
    $config['smtp_user'] = 'my email here';
    $config['smtp_pass'] = 'password here';
    $config['smtp_port'] = '465';

    $config['wordwrap'] = TRUE;

    $this->load->library('email');
    $this->email->initialize($config);
    
        $this->email->from('mailfrom', 'sample name');
        $this->email->to('mailto'); 

        $this->email->subject('sample email');
        $this->email->message('sample message for email.'); 

        $this->email->send();

        echo $this->email->print_debugger();
        
    }

结果是

Your message has been successfully sent using the following protocol: sendmail
    User-Agent: CodeIgniter
    Date: Tue, 29 Oct 2013 15:45:57 +0800
    From: "sample name" 
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <526f67b5f16b8@mobilemo.com>
    Mime-Version: 1.0
    Content-Type: text/plain; charset=iso-8859-1
    Content-Transfer-Encoding: 8bit

sample message for email.

它说电子邮件已成功发送,但我认为邮件没有到达我的收件箱。

谁能帮助我,我想我错过了一些东西。提前致谢。

4

2 回答 2

2

你可能想试试这个:

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'emailhere@gmail.com';
$config['smtp_pass'] = 'password Here';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "\r\n";

$this->load->library('email');
$this->email->initialize($config);

我刚刚更改了您的配置项。希望能帮助到你。

于 2013-10-29T10:47:53.897 回答
0

您是否在 Gmail 中启用了 SMTP 访问,如果我没记错的话,您必须单击 Gmail 中的某个复选框,例如“允许第 3 方使用此帐户发送邮件”。这也不是好的做法,因为 Gmail 会不断警告您有人试图访问您的帐户。

于 2013-10-29T08:02:42.520 回答