【问题标题】:sending email in CodeIgniter through gmail通过 gmail 在 CodeIgniter 中发送电子邮件
【发布时间】:2012-05-22 02:08:43
【问题描述】:

我正在按照教程使用 gmail 发送电子邮件,但是我得到的是一个页面,它只是挂起,甚至没有加载错误。我正在使用 MAMP,所以这可能是它无法正常工作的一个原因。

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());

        }

    }



}

【问题讨论】:

    标签: codeigniter mamp


    【解决方案1】:

    在你的 php.ini 文件中取消注释 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();
    

    希望这会奏效

    【讨论】:

    • 我的 php.ini 中没有该行,但是您提供的代码似乎有效。我想我需要添加 starttls 参数。
    • 试过了,效果很好。缩小范围,将$config['newline'] = "\r\n" 添加到我的电子邮件配置中为我修复了它。
    【解决方案2】:

    导致问题的行是:

    $this->email->set_newline("/r/n");
    

    删除它并尝试发送电子邮件。

    【讨论】:

    • 不,它仍然挂起。我需要在 gmail 中设置什么吗?
    • 您是否在 gmail 中启用了远程 SMTP?
    • 是的 pop 和 imap 已启用。另外,smtp.gmail.com 和 ssl://smtp.googlemail.com 有什么区别
    【解决方案3】:

    我自己成功地做到了这一点,但是通过发送 config/email.php 中的所有值来代替。那部分应该无关紧要。

    基本上,您是想通过@gmail 帐户还是您自己的域发送邮件?如果您尝试通过自己的域,则需要将 DNS 更改为相关的 google 设置:

    Create MX Records

    【讨论】:

      【解决方案4】:

      MAMP 不附带 openssl 扩展,但您可以自己创建它。详情见this教程

      【讨论】:

        【解决方案5】:

        首先使用标准 smtp 端口发布,并确保使用以下配置工作:

          函数索引(){

              $config = Array( '协议' => 'smtp', 'smtp_host' => 'smtp.googlemail.com', 'smtp_port' => 25, 'smtp_user' => '电子邮件', 'smtp_pass' => '通过' );

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

              $this->email->from('email', 'George'); $this->email->to('email'); $this->email->subject('嘿,这是一封电子邮件'); $this->email->message('这是邮件内容');

              $this->email->send(); }

        一旦您尝试过并且一切正常,请阅读以下内容:

        http://codeigniter.com/forums/viewthread/84689/

        【讨论】:

          猜你喜欢
          • 2012-03-22
          • 2012-01-07
          • 2023-03-19
          • 2012-12-07
          • 2014-01-24
          • 2010-09-07
          相关资源
          最近更新 更多