php - 在 Rest Client (Codeigniter) 中发送邮件

标签 php android codeigniter email

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

在我的 Controller 中我有这个:

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: <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="88bdbabeeebebfeabdeeb9beeab0c8e5e7eae1e4ede5e7a6ebe7e5" rel="noreferrer noopener nofollow">[email protected]</a>>
    Mime-Version: 1.0
    Content-Type: text/plain; charset=iso-8859-1
    Content-Transfer-Encoding: 8bit

sample message for email.

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

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

最佳答案

您可能想尝试一下这个:

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="12777f737b7e7a77607752757f737b7e3c717d7f" rel="noreferrer noopener nofollow">[email protected]</a>';
$config['smtp_pass'] = 'password Here';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "\r\n";

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

我刚刚更改了您的配置项。希望对您有所帮助。

关于php - 在 Rest Client (Codeigniter) 中发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19652493/

相关文章:

android - 如何从 onItemSelectedListener 获取自定义微调器的选定项目位置?

android - Flutter apk 在 android 设备中不起作用

MySQL服务器版本更新时语法问题

php - Laravel Elixir 包含更少的路径

php - 如果表中没有值,则查询应返回 0

php - 仅使用 PHP 对搜索结果进行分页

php - 我想添加来自不同列的值

android - 在 Android 中绘制弹丸运动路径

php - 无法加载请求的文件: category. php

php - 如何在基于 Codeigniter 的博客文章和图片库中使用 plupload