繁体   English   中英

使用Google和Codeigniter发送SMTP电子邮件时出错

[英]Error when sending smtp email with google and codeigniter

尝试为我的网站设置重置密码功能,但是我无法发送电子邮件而不会发生此错误。

无法使用PHP mail()发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件。

我使用gmail作为主机发送电子邮件。 这是用于发送电子邮件的功能的一部分。

$ 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');        
        } 

我也收到此错误::

消息:未定义的索引:主题

我不明白为什么会这样,请您帮助我。

您尝试发送两次电子邮件,第一次设置所有选项,第二次未设置

更改

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

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

如果有任何其他错误,则应该得到相关错误。

编辑:

还可以将$config['protocal']更改$config['protocal'] $config['protocol']以解决发送问题

您能否提供其余用于发送电子邮件的功能,您发布的所有内容看起来都是正确的... Message: Undefined index: Subject来自其他地方,可能会引起问题。

另外...这看起来似乎很明显,但是您实际上已经在某个地方加载了电子邮件类,对吗( $this->load->library('email); )...而不是仅对其进行初始化?

尝试这个

    $config = array('auth' => 'login',
        'username' => '***@gmail.com',
        'password' => '***password',
        'port' => '465',
        'ssl' => 'ssl');


    $request = $this->getRequest();


    if ($this->getRequest()->isPost()) {
        if ($form->isValid($request->getPost())) {
            try {
                $smtpHost = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
                $mail = new Zend_Mail();
                $mail->setBodyText($form->getValue('body'));
                $mail->setBodyHtml('');
                $mail->setFrom();
                $mail->addTo());
                $mail->setSubject('');
                $mail->send($smtpHost);
            } catch (Exception $e) {
                die($e);
            }
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM