Welcome Guest, Not a member yet? Register   Sign In
Email sending is slow
#1

[eluser]skunkbad[/eluser]
I've got a standard contact form, and it posts back to itself. Standard form validation happens. Form validation seems very quick. Once the actual email is being sent, it is taking a long time to show confirmation that it is done. I've tried this on all browsers for Windows XP and on different computers/locations, and they are equally slow. IE6 on Windows 2000 doesn't work. FF on Mac actually seemed pretty fast, but I'm not sure why.

I'd like to speed up the process, or perhaps having it do it in the background so the user experience doesn't lag, but I don't have any ideas. I don't remember this being so slow, but I recently did some work to my website, and that's when I noticed.

Check out what I have here, and let me know what you think:

The controller:
Code:
<?php
class Contact extends Controller {

    public function index()
    {
        $this->load->library('session');
        $session_token = $this->session->flashdata('submit_token');

        //If there was a submission, as opposed to a refresh, or somebody hitting the back button of their browser:
        if (
            $this->input->post('token') &&
            isset($session_token) &&
            $this->input->post('token') == $this->session->flashdata('submit_token')
            ){

            //Load CodeIgniter validation library
            $this->load->library('form_validation');
            $this->form_validation->set_error_delimiters('<li>', '</li>');
            //Set up validation rules
            $this->form_validation->set_rules('realname', 'NAME' , 'trim|required|xss_clean|callback__clean_field_model[formval_callbacks]');
            $this->form_validation->set_rules('email', 'EMAIL ADDRESS' ,'trim|required|xss_clean|callback__basic_email_validation_model[formval_callbacks]');
            $this->form_validation->set_rules('mesg', 'MESSAGE' , 'trim|required|xss_clean|callback__clean_field_model[formval_callbacks]');
            //Run the validation
            $this->load->model('formval_callbacks');
            if ($this->form_validation->run() == FALSE){
                $view_data['fail'] = 1;
                $column_b['fail'] = 1;
                $view_data['error_message_stack'] = validation_errors();
                //repopulate the form since errors occurred
                $fields = array(
                    'realname',
                    'email',
                    'mesg'
                );
                foreach($fields as $field){
                    if(!array_key_exists($field, $this->form_validation->_error_array)){
                        //Repopulate only the fields that passed validation
                        $view_data[$field] = set_value($field);
                    }else{
                        //Set up good field indicator (asterisk) to be green
                        $error_array_keys["$field"] = $field;
                    }
                }
                //A resubmission is going to need another form token
                $token = md5(uniqid(rand(), TRUE));
                $this->session->set_flashdata('submit_token', $token );
                $view_data['token'] = $token;
            }else{
                $view_data['submit'] = 1;
                $column_b['submit'] = 1;
                $confirmation_message =    "<h3>Thank You!</h3>
                                        <p>Thank you for sending me a message.<br />I will get back to you shortly.</p>";
                //Show the thank you message
                $view_data['confirmation_message'] = $confirmation_message;
                // send the email
                $this->load->library('email');
                $this->email->from( set_value('email') , set_value('realname') );
                $this->email->to( '[email protected]' );
                $this->email->subject('BWD Contact Message ' . date("M j, Y"));
                $built_message['realname'] = set_value('realname');
                $built_message['email'] = set_value('email');
                $built_message['mesg'] = nl2br(set_value('mesg'));
                $this->email->message($this->load->view('contact_email', $built_message, TRUE));
                $this->email->send();
            }

        }else{
            //If no form submission, then user here for the first time, and needs a form token
            $token = md5(uniqid(rand(), TRUE));
            $this->session->set_flashdata('submit_token', $token );
            $view_data['token'] = $token;
        }

        // insert page specific data into template
        $data = array(
            'title' => 'Brian\'s Web Design - Contact Brian',
            'robots' => 'index,follow',
            'style_sheet_names' => array(
                                        'css/style.css',
                                        'css/page_specific/contact/screen.css'
            ),
            'media_targets' => array(
                                    'screen',
                                    'screen'
            ),
            'javascripts' => array(
                                    'js/target_blank.js',
                                    'js/contact_write.js',
                                    'js/contact_validate.js'
            ),
            'slogan' => 'I\'m really pretty easy to get ahold of ...',
            'content' => $this->load->view('contact', $view_data, TRUE )
        );

        $this->load->view('template_content', $data );
    }


Messages In This Thread
Email sending is slow - by El Forum - 09-28-2009, 05:35 PM
Email sending is slow - by El Forum - 09-28-2009, 06:20 PM
Email sending is slow - by El Forum - 09-28-2009, 07:33 PM
Email sending is slow - by El Forum - 10-10-2009, 03:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB