0

this is my controller class, that try to send a contact us email to admin,It keeps returning nothing, i've checked the the http response in the developer tool but i don't see anything and my code seems correct.

public function sendmail(){
    $this->load->library('email');
    $email = $this->input->post('email');
    $message = $this->input->post('message');
    $subject = $this->input->post('subject');
    $config = array(
        'protocol' => 'sendmail',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => '*******@gmail.com',
        'smtp_pass' => '*********',
    );


    $this->email->initialize($config);
    $this->email->set_mailtype('html');
    $this->email->from($email,'User');
    $this->email->to($this->config->item('ver_email'));
    $this->email->subject($subject);

    $this->email->message($message);
    if($this->email->send()){
        echo "<p>sent</p>"; 
    }

    else{
        $error_result = $this->email->print_debugger();
        echo "<p>$error_result</p>";
    }



}

this is my script that handles the request

 $("#mybtn").click(function(e){ 
 //e.preventDefault();   
 var email = $('#c-form-1-email').val();
 var subject = $('#c-form-1-subject').val();
 var message = $('#c-form-1-message').val();
  $(document).ajaxStart(function(){
    $("#loader").css("display", "block")
});


$.ajax({
        type:'POST',
        data:{email:email, message:message, subject:subject},
        url:'http://www.quickvelo.com/quickvelo/velo/sendmail',
        dataType: "html",

        success: function(data) {
           alert(data);
        }


});

Here is my html form

     <form>
        <div class="form-group">
           <label for="c-form-1-email">Email: 
               <span class="c-form-1-error"></span>
           </label>
             <input type="text" name="email" 
             placeholder="Your email address..." 
             class="c-form-1-email form-control" id="c-form-1-email">
        </div>
        <div class="form-group">
            <label for="c-form-1-subject">Subject: 
            <span class="c-form-1-error"></span></label>
            <input type="text" name="subject"placeholder="Message       subject..." class="c-form-1-subject form-control" id="c-form-1-subject">enter code here    
                            </div>
                            <div class="form-group">
                                <div id="loader"> <img width="70" height="70" src="<?php echo base_url('assets/img/loader.gif'); ?>" /> </div>
                                <label for="c-form-1-message">Message: <span class="c-form-1-error"></span></label>
                                <textarea name="message" placeholder="Message text..." class="c-form-1-message form-control" id="c-form-1-message"></textarea>
                            </div>
                            <button type="button" value="submit" id="mybtn" class="btn con_s">Send Message</button>


                        <form>
  • Turn on error reporting and see, where your code breaks. PS: `data:{email:email, message:message, subject:subject},` What is this line? – Peon Mar 09 '17 at 08:58
  • If you check the console when you run your code (as you can in this fiddle: http://jsfiddle.net/avtgsk8t/) you'll see an error: `No 'Access-Control-Allow-Origin' header is present on the requested resource`. This is because you're making a cross-domain request with JS. To fix the problem you need to modify your PHP code to either return data in JSONP format, or add CORS headers to the response. See the duplicate for more information – Rory McCrossan Mar 09 '17 at 09:00

0 Answers0