通过 gmail 在 CodeIgniter 中发送电子邮件

2023-12-02

我正在按照教程使用 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());

        }

    }



}

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

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

    $this->load->library('email', config);
    $this->email->from('[email protected]', 'George');
    $this->email->to('[email protected]');
    $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();

希望这会起作用

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 gmail 在 CodeIgniter 中发送电子邮件 的相关文章

随机推荐