开发者

Error when sending smtp email with google and codeigniter

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-&g开发者_Go百科t;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


Can you give the rest of the function you're using to send the email, everything you've posted looks correct... the Message: Undefined index: Subject is coming from somewhere else and might be causing problems.

Also... this may seem obvious, but you have actually loaded the email class somewhere, right ($this->load->library('email);)... rather than just initialized it?


try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜