Welcome Guest, Not a member yet? Register   Sign In
trigger send mail with Ajax not working
#1

[eluser]elaniobro[/eluser]
I've gotten pretty far with this. I got the page making the ajax call.

Prior to putting ajax in, sending an e-mail was no problem. Once I put it in, it no longer sends. It will still validate, however if you pass the validation, it will just load the success view and not send an e-mail.

controller:
Code:
<?php
    class Email extends Controller
    {
    
        function Email()
        {
            parent::Controller();    
        }
        
        function index()
        {
            $this->load->view('email_view');    
        }
        
        function send()
        {
            
            $this->load->library('form_validation');
            
            //field name, error message, validation rules
            $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
            $this->form_validation->set_rules('fullName', 'full name', 'trim|required|min_length[5]');
            
            if($this->form_validation->run() == FALSE)
            {
                
                $this->load->view('email_view');
                
            }else{
                //validaiton has past, send e-mail
                $fullName = $this->input->post('fullName');
                $email = $this->input->post('email');
                $subject = $this->input->post('subject');
                $message = $this->input->post('message');
            
                $config = Array(
                            'protocol' => 'sendmail',
                            'smtp_host' => 'smtp.example.com',
                            'smtp_port' => 143,
                            'smtp_user' => '[email protected]',
                            'smtp_pass' => 'start123'    
                                );
                $this->load->library('email');
    
                $this->email->from($email, $fullName);
                $this->email->to('[email protected]');            
                $this->email->subject($subject);
                $this->email->message($message);
                
                $this->load->library('email', $config);
                $this->email->set_newline("\r\n");
                
                if($this->input->post('ajax'))
                {
                    $this->load->view('emailSucess_view');
                }else{
                    $this->load->view('email_view');
                }
            
            
    
            }
        }
    }
?>
#2

[eluser]elaniobro[/eluser]
view:
Code:
<div class="popup-container" id="contact-container">
                        <div class="watermark">
                            &lt;?=img(array('src'=>'img/footer/trybuch_contact_a.png','alt'=>'contact'));?&gt;
                        </div>
                        <div class="close">
                            &lt;?= anchor('',
                                        img(array(
                                                  'src'=>'img/nav/nav_close_a.gif',
                                                  'id'=>'contactBack',
                                                  'border'=>'0',
                                                  'alt'=>'Close'
                                                  )
                                            ),
                                        array(                                          
                                              'onmouseover'=>'contactBack'.'.src='."'".base_url().'img/nav/nav_close_b.gif'."'".';'.'"',
                                              'onmouseout'=>'contactBack'.'.src='."'".base_url().'img/nav/nav_close_a.gif'."'".';'.'"'
                                              )
                                        );
                             ?&gt;
                        
                        </div>
                        <div class="clear"></div>
                            <div id="contact-form">
                                <div class="title">
                                    &lt;?= img(array('src'=>'img/footer/contact/trybuch_title_contact.gif','alt'=>'Contact Form'));?&gt;
                                </div>
                                &lt;?= form_open('email/send');?&gt;
                                
                                <p>&lt;input&gt;&lt;label class="contact-label">email</label></p>
                                <p>&lt;input&gt;&lt;label class="contact-label">full name</label></p>
                                <p>&lt;input&gt;&lt;label class="contact-label">subject</label></p>
                                <p>&lt;textarea&gt;So tell me what is on your mind....&lt;/textarea&gt;&lt;/p>
                                &lt;?= form_submit('submit','Send','id="submit"');?&gt;
                                &lt;?= form_close();?&gt;
                                &lt;?= validation_errors('<p class="contact-error">');?&gt;
                            </div>
                    </div>
                    [removed]
                        $('#submit').click(function()
                        {

                            var contact_data =
                            {
                                fullName: $('#fullName').val(),
                                email: $('#email').val(),
                                subject: $('#subject').val(),
                                message: $('#message').val(),
                                ajax: '1'
                                
                            };
                        
                            $.ajax({
                                url: "&lt;?php echo site_url('email/send');?&gt;",
                                type: 'POST',
                                data: contact_data,
                                success: function(msg){
                                    $('#contact-container').html(msg);
                                }
                            });
                            return false;
                            
                        });
                    [removed]
#3

[eluser]Kamarg[/eluser]
You seem to be missing $this->email->send() within your send function.
#4

[eluser]elaniobro[/eluser]
[quote author="Kamarg" date="1268859577"]You seem to be missing $this->email->send() within your send function.[/quote]


oh man, thanks for that.. I guess I deleted that line accidentally and did not notice when I started implementing the ajax Tongue

It is usually the most obvious. Thanks Kamarg!

Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB