在Rest Client中发送邮件(Codeigniter)

时间:2013-10-29 07:50:03

标签: php android codeigniter email

我正在为我的Android应用程序开发Web服务,我很难在我的电子邮件功能上运行良好。 我按照本教程HERE

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

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.

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

任何人都可以帮助我,我想我错过了什么。 提前谢谢。

2 个答案:

答案 0 :(得分: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);

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

答案 1 :(得分:0)

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