使用google和codeigniter发送smtp电子邮件时出错 [英] Error when sending smtp email with google and codeigniter

查看:806
本文介绍了使用google和codeigniter发送smtp电子邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图为我的网站设置一个重置密码功能,但是我无法通过发送邮件而没有发生此错误。


无法使用PHP邮件()发送电子邮件。
您的服务器可能未配置为使用此方法发送邮件。
<主持人发送电子邮件。这是用于发送电子邮件的功能的一部分。



$ user_email = $ this-> input-> post('email_address');

  $ query = $ this-> db-> get_where('account',array('email_address'=> $ user_email) ); 
if($ query){
$ config ['protocal'] ='smtp';
$ config ['mail_path'] ='ssl://smtp.googlemail.com';
$ config ['smtp_host'] ='ssl://smtp.googlemail.com';
$ config ['smtp_port'] ='465';
$ config ['smtp_user'] ='USEREMAIL';
$ config ['smtp_pass'] ='密码';
$ config ['charset'] =utf-8;
$ config ['mailtype'] =html;
$ config ['newline'] =\r\\\
;

$ this-> email-> initialize($ config); ('matthew.attanasio135@gmail.com','马修'); b

$ this-> email->
$ this-> email->到($ user_email);

$ this-> email-> subject('Email Test');
$ this-> email-> message('< h1>测试电子邮件类别< h1>');

$ this-> email-> send();
if(!$ this-> email-> send()){
show_error($ this-> email-> print_debugger());
}
else {
echo('DONE');
}

我也遇到这个错误::


消息:未定义的索引:Subject


我不明白这是为什么发生了什么事你能否帮我解答谢谢。

解决方案

您试图发送邮件两次,选项已设置,第二个选项未设置

更改

  $这 - >的电子邮件 - >置于(); 
if(!$ this-> email-> send()){
show_error($ this-> email-> print_debugger());



<$ p ($!this-> email-> send()){
show_error($ this-> email-> print_debugger()); $ p>
}

如果有任何遗漏,您应该会收到相关错误。



编辑:

也将 $ config ['protocal'] 更改为 $ config ['protocol'] 来解决发送问题

trying to make a reset password function for my website however I cant get past sending an email without this error occuring.

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

I am using gmail as the host to send the email. Here is the part of the function that is used to send the email.

$user_email = $this->input->post('email_address');

    $query = $this->db->get_where('account', array('email_address' => $user_email));
    if($query) {
        $config['protocal'] = 'smtp';
        $config['mail_path'] = 'ssl://smtp.googlemail.com';
        $config['smtp_host'] = 'ssl://smtp.googlemail.com';
        $config['smtp_port'] = '465';
        $config['smtp_user'] = 'USEREMAIL';
        $config['smtp_pass'] = 'PASSWORD';
        $config['charset'] = "utf-8";
        $config['mailtype'] = "html";
        $config['newline'] = "\r\n";

        $this->email->initialize($config);

        $this->email->from('matthew.attanasio135@gmail.com', 'Matthew');
        $this->email->to($user_email); 

        $this->email->subject('Email Test');
        $this->email->message('<h1>Testing the email class.<h1>');  

        $this->email->send();
        if ( ! $this->email->send()) {
            show_error($this->email->print_debugger());
        } 
        else {
            echo('DONE');        
        } 

I am also getting this error::

Message: Undefined index: Subject

I do not understand why this is happening could you please help me out thank you.

解决方案

You're trying to send the email twice, the first time all your options are set and the second they aren't

change

    $this->email->send();
    if ( ! $this->email->send()) {
        show_error($this->email->print_debugger());
    }

to

    if ( ! $this->email->send()) {
        show_error($this->email->print_debugger());
    } 

You should then get relevant errors if any remain.

Edit:

also change $config['protocal'] to $config['protocol'] to fix the sending problem

这篇关于使用google和codeigniter发送smtp电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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