ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Contact form not working after upgrade from EE 2.4.0 to 2.7.1

October 08, 2013 8:45am

Subscribe [2]
  • #1 / Oct 08, 2013 8:45am

    Scott-Parks

    14 posts

    I’m upgrading from EE 2.4.0 to EE 2.7.1 - the upgrade has gone very well, but I’ve run into a problem with my email contact form.

    The form seems to be functioning, but it won’t actually send the email. I’m using a custom form that I’m using Codeigniter methods directly.

    I read about the {XID_HASH} being added to a hidden input.  That worked for one of my other forms on the site (not an email form), but it hasn’t worked on my email contact form.

    I’ve tried setting the fields for email configuration and tried different protocols, PHP Mail and Sendmail, don’t have smtp set up on the server.  I don’t think it’s the server config, because EE 2.4.0 was working just fine.

    I’ve also tried using the EE Communicate form to send an email through EE’s admin console and that email did not go through.

    I then tried going to another website altogether, on the same staging server though, and tried sending an email through a form that also uses Codeigniter.  The email went through no problem.  I was using the Codeigniter email library with $this->email->send(); doing the send portion.  In EE I’m using $this->EE->email->send();

    Has this changed?

    Here’s how I’m using the XID hash in the hidden field.  Like I said, this worked for non-email form, but on my contact form it’s not.
    <input type=“hidden” id=“XID” name=“XID” value=”{XID_HASH}”>

    Do I need to do something in my email contact form validation with the XID id?  Am I not processing that correctly?  Is that even needed?

    Thankfully this is only on a staging server to test the upgrade, but so far I haven’t had any luck fixing it.

    Thanks in advance for any suggestions.

  • #2 / Oct 08, 2013 11:10am

    Scott-Parks

    14 posts

    Just figured it out.  Had to change my Codeigniter email config from $config[‘protocol’] = ‘sendmail’; to $config[‘protocol’] = ‘mail’; and now email is going through fine. I think there was a mis-match in my EE email configuration setting to use “PHP Mail” and my old script was trying to use sendmail.

    Setting it the same seems to have fixed the issue.

  • #3 / Feb 10, 2014 8:44am

    pumkin

    4 posts

    I’m bringing this up again because although my issue is slightly different, the subject is the same, ie. having upgraded from 2.5.5 to 2.7.3, SMTP email is no longer working, either from our standard forms on the site, or from the Communicate tool in the manager.

    We’re using our own remote SMTP server, and still have the 2.5.5 version running on a separate machine - on that installation, email works fine. What happens on the new system is that the email works for around 24 hours, and then stops. We get a different error message depending on which port setting we use (the port setting wasn’t an option on 2.5.5, though I assume it was 25 by default).

    Our hosts are at a loss too, and we’ve pretty much ruled out any problem with the SMTP server itself. We aren’t using any custom mailing scripts either.

    I note from the answer above that the CodeIgniter protocol config needed changing - is it likely the same solution could apply here, and where would we make the change?

    Edit: Just been doing some testing with different ports, and the most meaningful error message appears on port 587, which reads:

    Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first
  • #4 / Feb 10, 2014 9:26am

    Scott-Parks

    14 posts

    I use a php enabled template in Expression Engine to process the contact form using the Codeignitor framework from within EE.  I reference a template uploaded to a custom directory within EE. I believe I put it in /system/expression/views/custom/forms/yourcontactform.php

    This is pretty much straight from the Codeigniter documentation on Form validation. The only difference within EE is that the methods required $this->EE-> to be added.  The “EE->” portion is different than working straight from Codeigniter.

    The portion of the code that starts to send the email is just after the ->load->library(‘email’) part. The configuration follows.

    Hope this helps!

    Here’s the basics of my code on the contact page.

    <?php
    
    $this->EE->load->library('form_validation');
    $this->EE->form_validation->set_error_delimiters('<div  red; font-weight: bold;">', '</div>');
    
    // set your validation rules according to Codeigniter documention
    $this->EE->form_validation->set_rules('name', 'Name', 'required|max_length[50]|xss_clean');
    $this->EE->form_validation->set_rules('email_subject', 'Email Subject', 'required|max_length[50]|xss_clean');
    $this->EE->form_validation->set_rules('email', 'Email Address', 'required|valid_email|max_length[50]|xss_clean');
    
    
    if ($this->EE->form_validation->run() == FALSE)
    {
     $this->EE->load->view('custom/forms/email_contact');
    }
    else
    {
     $this->EE->load->library('email');
     
     // protocol is what I changed from sendmail to mail 
     $config['protocol'] = 'mail';
     $config['charset'] = 'utf-8';
     $config['mailtype'] = 'text';
     $config['clrf'] = '\r\n';
     $config['newline'] = '\r\n';
     $config['wordwrap'] = TRUE;
    
     $this->EE->email->initialize($config);
     
     $this->EE->email->from(.(JavaScript must be enabled to view this email address));
     $this->EE->email->to(.(JavaScript must be enabled to view this email address));
      
    
     $this->EE->email->subject($this->EE->input->post('email_subject'));
    
     $message = 'this is the body of the message';
     
    
     $this->EE->email->message($message); 
    
     $this->EE->email->send();
    }
    ?>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases