• GoDaddy Community
  • VPS & Dedicated Servers
  • VPS & Dedicated Servers

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Highlighted

    Simple php form mail() script taking 60 seconds to run

    I created a new server, installed a LAMP stack, and uploaded my website. All is well except that my "contact" form takes a full minute to process. The exact same website, form and all, installed at a different host (non-godaddy) runs in a flash when one clicks "submit".

     

    I confess to being a rank novice regarding all things LAMP, but does anyone have any ideas and/or suggestion for diagnostic steps/tools? Even just pointing me to some good info would be helpful.

     

    One suggestion I read was to change to google DNS nameservers. I did that but it made no difference.

     

    The php script follows, if that is any help. Thanks!

    ----------------------------------------------------------------------------------

     

    <?php
     
    /* =====================================================
     * change this to the email you want the form to send to
     * ===================================================== */
    $email_to = "me@myemail.com";
    $email_subject = "Contact Form submitted";
     
    if(isset($_POST['email']))
    {
     
        function return_error($error)
        {
            echo $error;
            die();
        }
     
        // check for empty required fields
        if (!isset($_POST['name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['message']))
        {
            return_error('Please fill in all required fields.');
        }
     
        // form field values
        $name = $_POST['name']; // required
        $email = $_POST['email']; // required
        $contact_number = $_POST['contact_number']; // not required
        $message = $_POST['message']; // required
     
        // form validation
        $error_message = "";
     
        // name
        $name_exp = "/^[a-z0-9 .\-]+$/i";
        if (!preg_match($name_exp,$name))
        {
            $this_error = 'Please enter a valid name.';
            $error_message .= ($error_message == "") ? $this_error : "<br/>".$this_error;
        }       
     
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
        if (!preg_match($email_exp,$email))
        {
            $this_error = 'Please enter a valid email address.';
            $error_message .= ($error_message == "") ? $this_error : "<br/>".$this_error;
        }
     
        // if there are validation errors
        if(strlen($error_message) > 0)
        {
            return_error($error_message);
        }
     
        // prepare email message
        $email_message = "Form details below.\n\n";
     
        function clean_string($string)
        {
            $bad = array("content-type", "bcc:", "to:", "cc:", "href");
            return str_replace($bad, "", $string);
        }
     
        $email_message .= "Name: ".clean_string($name)."\n";
        $email_message .= "Email: ".clean_string($email)."\n";
        $email_message .= "Contact number: ".clean_string($contact_number)."\n";
        $email_message .= "Message: ".clean_string($message)."\n";
     
        // create email headers
        $headers = 'From: '.$email."\r\n".
        'Reply-To: '.$email."\r\n" .
        'X-Mailer: PHP/' . phpversion();
        if (@mail($email_to, $email_subject, $email_message, $headers))
        {
            echo 'Form submitted successfully.';
        }
        else
        {
            echo 'An error occured. Please try again later.';
            die();       
        }
    }
    else
    {
        echo 'Please fill in all required fields.';
        die();
    }
    ?>
    14 REPLIES 14
    Highlighted
    Employee
    Employee

    Re: Simple php form mail() script taking 60 seconds to run

    How are you measuring the time?  I am trying to understand what you are seeing? Is the screen hung for 60 seconds? Or does it take 60 seconds for you to receive the email?

     

     


    Thanks,

    Brad

    Dev Manger - Cloud Servers
    Highlighted

    Re: Simple php form mail() script taking 60 seconds to run

    Sorry I wasn't clear. Delivery time is not the issue; it's send time. Normally, there is just a brief moment between clicking "submit" and seeing "Your message was sent". However, on my cloud server, once "submit" is clicked, it is a full minute or more before the "message sent" notice appears. The form works and I receive the email, but that one-minute hang is not going to work for the users.

     

    Not sure what to troubleshoot. Any insight appreciated. Thanks.  

    Highlighted
    Employee
    Employee

    Re: Simple php form mail() script taking 60 seconds to run

    I have a few more questions and then I will hopefully be able to provide some guidance. 

     

    What operating system did you install?

    Or did you install the Bitnami Lamp Stack from our applications?

     

    One thing I am tempted to do is instrument your script with some timestamps to see where it is getting hung because looking at the PHP code, there is nothing there that should take any time at all. Our mail relay servers will accept the mail and schedule it for delivery instantaneously.

     

    Brad

     


    Thanks,

    Brad

    Dev Manger - Cloud Servers
    Highlighted

    Re: Simple php form mail() script taking 60 seconds to run

    Thanks, Brad. It's running Ubuntu 14.4 and I installed the lamp components from your apps. Did not use Bitnami. You can try it live at shred-911.com.

    Highlighted
    Employee
    Employee

    Re: Simple php form mail() script taking 60 seconds to run

    @DogFlight

     

    I was able to reproduce your problem. The issue is that sendmail is doing a reverse dns lookup using the private IP address assigned to your server. The simplest way to fix this is to edit your /etc/hosts file and add an entry for your private IP. 

     

    /etc/hosts:

    127.0.0.1       localhost
    10.x.x.x   shred-911.com

    ^^ Replace 10.x.x.x with your private IP, which you can get from the "overview" tab in the control panel at https://cloud.godaddy.com.

     

    We will work on a fix that doesn't require this workaround, but this will get you up and running.

     

    Cheers,

     

    Brad

     


    Thanks,

    Brad

    Dev Manger - Cloud Servers
    Highlighted

    Re: Simple php form mail() script taking 60 seconds to run

    Well, darn. I made the edit, but no difference. Shutdown, powered off then on, still no change. Any other ideas? I had high hopes for this one. Thanks for your efforts!

    Highlighted
    Employee
    Employee

    Re: Simple php form mail() script taking 60 seconds to run

    Can you post the contents of your /etc/hosts file?

     

    Also, can you send an email and then grab the last 20 lines of your mail log and post? You can do that by running:

    tail -n20 /var/log/mail.log

    You will need to elevate to root to access the log:

    sudo su -

    Cheers,

     

    Brad

     

     


    Thanks,

    Brad

    Dev Manger - Cloud Servers
    Highlighted

    Re: Simple php form mail() script taking 60 seconds to run

    Try as I might, I cannot get this forum to allow me to paste text; no matter the method, it generates a message telling you to use ctrl-v (even when you use ctrl-v). If I paste into a code box and then attempt to post, I get an html error that says nothing but "there was an error". Is there an email address where I can send the info you need?

    Highlighted

    Re: Simple php form mail() script taking 60 seconds to run

    Chrome allows me to paste in the reply box (Edge didn't), but when I post I still get the error.

     

    1) Trying to attach a file...

     

    2) And then this: 

    Correct the highlighted errors and try again.

    • The file DogFlight_Files_4_Brad.txt does not have a valid extension for an attachment and has been removed. jpg,gif,png are the valid extensions.

     

    3) Okay, resending as a "jpg" to read with your favorite text viewer.

     

    4) Now, when I click Post, I get: 

    An error occurred while processing your request.

    Reference #97.250ad817.1466605468.7673b1b8

     

    5) Removing attachment and throwing hands up in disgust. Will try posting just this message.

     

    6) Unbelievable. Now I get this: Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied.

    Highlighted
    Employee
    Employee

    Re: Simple php form mail() script taking 60 seconds to run

    Email me at devfeedback [at] godaddy

    I'll let the forum team know about the probless you are having

    Thanks,

    Brad

    Dev Manger - Cloud Servers
    Highlighted
    Community Manager
    Community Manager

    Re: Simple php form mail() script taking 60 seconds to run


    @DogFlight wrote:

    Chrome allows me to paste in the reply box (Edge didn't), but when I post I still get the error.

     

    1) Trying to attach a file...

     

    2) And then this: 

    Correct the highlighted errors and try again.

    • The file DogFlight_Files_4_Brad.txt does not have a valid extension for an attachment and has been removed. jpg,gif,png are the valid extensions.

     

    3) Okay, resending as a "jpg" to read with your favorite text viewer.

     

    4) Now, when I click Post, I get: 

    An error occurred while processing your request.

    Reference #97.250ad817.1466605468.7673b1b8

     

    5) Removing attachment and throwing hands up in disgust. Will try posting just this message.

     

    6) Unbelievable. Now I get this: Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied.


    Hey @DogFlight,

    Sorry for the issues you're experiencing with posting! We've reported them and hope to have them fixed asap. Thanks!

    Rachel

    GoDaddy Community Manager | 24/7 support available at x.co/247support | Remember to give kudos to others and accept a solution if someone answered your question.
    Highlighted
    Community Manager
    Community Manager

    Re: Simple php form mail() script taking 60 seconds to run


    @DogFlight wrote:

    Chrome allows me to paste in the reply box (Edge didn't), but when I post I still get the error.

     

    1) Trying to attach a file...

     

    2) And then this: 

    Correct the highlighted errors and try again.

    • The file DogFlight_Files_4_Brad.txt does not have a valid extension for an attachment and has been removed. jpg,gif,png are the valid extensions.

     

    3) Okay, resending as a "jpg" to read with your favorite text viewer.

     

    4) Now, when I click Post, I get: 

    An error occurred while processing your request.

    Reference #97.250ad817.1466605468.7673b1b8

     

    5) Removing attachment and throwing hands up in disgust. Will try posting just this message.

     

    6) Unbelievable. Now I get this: Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied.


    Hi @DogFlight,

    @Would you please try to post your file again. We think we fixed the issue. Please @mention me in your post so I know if it worked or not. Thanks much for your help!

    Rachel

    GoDaddy Community Manager | 24/7 support available at x.co/247support | Remember to give kudos to others and accept a solution if someone answered your question.
    Highlighted

    Re: Simple php form mail() script taking 60 seconds to run

    @RachelM

     

    Just tried an attachment again. The first attempt failed because it was a text file with a .jpg extension. Your red banner appeared saying that was a no-no, as designed, I reckon.

     

    Unfortunately, when I attempted a true text file with a .txt extension, I got a blank screen and then the following error:

     

    An error occurred while processing your request.

    Reference #97.250ad817.1466648038.7a52ea0b

     

    I'm back using Edge, and as it sucks in many ways, I can try again with Chrome or Opera, if you think it would make any difference on the upload.

     

    Oh, and hey, the paste function works now while using Edge.

    Highlighted
    Community Manager
    Community Manager

    Re: Simple php form mail() script taking 60 seconds to run

    Thanks for trying again @DogFlight! I'll get your feedback to our team and have them keep working on getting this fixed. Have a good day!

    Rachel

    GoDaddy Community Manager | 24/7 support available at x.co/247support | Remember to give kudos to others and accept a solution if someone answered your question.