通过gmail在CodeIgniter中发送电子邮件 [英] sending email in CodeIgniter through gmail

查看:242
本文介绍了通过gmail在CodeIgniter中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照一个教程使用gmail发送电子邮件,但我得到的是一个刚刚挂起,甚至不加载错误的页面。我使用MAMP,这可能是它不工作的原因。

I'm following a tutorial to send emails using gmail, however what I get is a page that just hangs and doesn't even load an error. I'm using MAMP so that may be a reason why it isnt working.

class Email extends CI_Controller{

    public function __construct()
   {
        parent::__construct();

   }

    function index(){

        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'email',
            'smtp_pass' => 'pass'
        );

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

        $this->email->set_newline("/r/n");
        $this->email->from('email', 'George');
        $this->email->to('email');
        $this->email->subject('hey this is an email');
        $this->email->message('this is the content of the email');

        if($this->email->send()){

                echo 'Your message was sent';

        }else{

            show_error($this->email->print_debugger());

        }

    }



}


推荐答案

在您的php.ini文件中取消注释extension = php_openssl.dll

in your php.ini file uncomment extension=php_openssl.dll

$config = Array(
            'protocol'  => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => '465',
            'smtp_user' => 'someuser@gmail.com',
            'smtp_pass' => 'password',
            'mailtype'  => 'html',
            'starttls'  => true,
            'newline'   => "\r\n"
        );

    $this->load->library('email', config);
    $this->email->from('email@gmail.com', 'George');
    $this->email->to('email@gmail.com');
    $this->email->subject('hey this is an email');
    $this->email->message('this is the content of the email');
    $this->email->send();
    echo $this->email->print_debugger();

希望这会奏效

这篇关于通过gmail在CodeIgniter中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆