Welcome Guest, Not a member yet? Register   Sign In
SOLVED: Email sending twice
#1

[eluser]wakey[/eluser]
I've just started using the email class for a contact form. Got it up and running nicely, however, the form is appearing twice in my inbox rather than once.

Can anyone help me here?

My controller
Code:
$name = $this->input->post('name');
                $email = $this->input->post('email');
                $message = $this->input->post('message');
                
                $this->load->library('email');
            
                $config['protocol'] = 'sendmail';
                $config['mailpath'] = '/usr/sbin/sendmail';
                $config['charset'] = 'iso-8859-1';
                $config['wordwrap'] = TRUE;
                
                $this->email->initialize($config);
    
                $this->email->from($email, $name);
                $this->email->to('[email protected]');
                
                $this->email->subject('Message from Website');
                $this->email->message($message);
                
                $this->email->send();
                
                if ( ! $this->email->send())
                {
                    $this->session->set_flashdata('emailerror', 'There was a problem whilst attempting to send the contact form. Please try again.');
                    redirect('contact');
                }
                else
                {
                    redirect('contact/sent');
                }
#2

[eluser]wakey[/eluser]
<del>Ahh, it seems to be something to do with the redirect upon success. Any idea why this redirect would cause it to send twice?</del>

Forget that. It seems to be something to do with the if and else statement. If I remove it, it only sends once!
#3

[eluser]wakey[/eluser]
Sorry for all the posts but this may help someone. I changed the end of my code to -

Code:
$sent = $this->email->send();
                
                if ($sent == true)
                {
                    $this->sent();
                }
                else
                {
                    $this->session->set_flashdata('emailerror', 'There was a problem whilst attempting to send the contact form. Please try again.');
                    redirect('contact');
                }

and it only sends once.
#4

[eluser]Pschilly[/eluser]
This doesnt work... Atleast not for me.




Theme © iAndrew 2016 - Forum software by © MyBB