1

I have created a PHP email script for an already created website. I will include the HTML form and the JavaScript related to it and the PHP script I created. My problem is when I install it on my hostgator host and my localhost, it works fine.

But when I install it in the host that my friend uses, it gives a 500 internal server error. What could cause such an error?

Html:

<form action="mailer.php" method="post" name="form1" id="form"  class="form-full-width contact-form">
  <div class="row">
    <div class="col-xs-12 col-sm-12">
      <div class="form-group">

        <input placeholder="YOUR NAME*"  type="text" id="contact-name" name="name"  required  data-validate="^[ا-ی\w\s]{2,30}$" />

      </div>
    </div>
    <div class="col-xs-12 col-sm-12">
      <div class="form-group">

        <input  placeholder="Email*" type="email" id="contact-email" name="from" required  data-validate="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />

      </div>
    </div>
    <div class="col-xs-12 col-sm-12">
      <div class="form-group">

            <input placeholder="ORDER ID*" type="text" id="contact-subject"  name="order"  aria-describedby="name-format" required  />
      </div>
    </div>
    <div class="col-xs-12 col-sm-12">
      <div class="form-group">

        <textarea placeholder="YOUR MESSAGE*" id="contact-message" name="message" required   data-validate=".{2,400}$"></textarea>
      </div>
    </div>
    <div class="col-xs-12 col-sm-12 text-left">
      <div class="wrap-main">
        <input name="Submit" type="submit" id="submit" class="btn btn-main btn-primary btn-lg uppercase" value="Send Message"/>
      </div>
    </div>
  </div>
</form>

Javascript:

 $('#contact-form').on('submit', function(e) {
    e.preventDefault();
    // we clear error messages
    $(this).find('.error').removeClass('error');
    $(this).find('.err_msg').fadeOut(200);

    // validate form
    var validation = validate_contact(e);

    for (var i = 0; i < validation.length; i++) {
        $(validation[i]).addClass('error');
    }

    if (validation.length) {
        $('body, html').animate({
            'scrollTop': $(validation[0]).offset().top - 100
        }, 'easeInCube', function() {
            $(this).select();
        });
        return false;
    } else {
        submit_form(e);
        return true;
    }
});

function validate_contact(e) {
    var $form = $(e.target);
    var rule, val, bad_fields = new Array();
    $form.find('input, textarea').each(function() {
        rule = $(this).data('validate');
        if (!rule) return;

        val = $(this).val();
        if (!val.match(rule)) {
            bad_fields.push(this);
        }
    });
    return bad_fields;
}

PHP:

<?php
    $admin_email = "1991praneeth@gmail.com"; // Enter your email adress here
    $name = $_REQUEST["name"];
    $message = $_REQUEST["message"];
    $from = $_REQUEST["from"];
    $order = $_REQUEST["order"];
    $message = str_replace("\n", "<br />", $message);
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'To: Amazon Auto Sales <'.$admin_email.'>' . "\r\n";
    $headers .= 'From: '.$name.' <'.$from.'>' . "\r\n";
    $message1 = '<html><body style="font-family:verdana;">';
    $message1 .= '<div style="width:600px; height:50px; text-align:center; background:#FFF;">';
    $message1 .= '<h2 style="color:#D2583E; font-size:18px;">New Email from Amazon Auto Sales Form!</h2></center>';
    $message1 .= '</div>';
    $message1 .= '<div style="width:600px; border:1px solid #999; margin-bottom:10px; padding:10px;">';
    $message1 .= '<b>From</b>';
    $message1 .= '

 - '.$name.'<br/>';
    $message1 .= '<b>User Email</b>';
    $message1 .= ' - '.$from.'<br/>';
    $message1 .= '<b>Order ID</b>';
    $message1 .= ' - #'.$order.'<br/>';
    $message1 .= '<br/>'.$message.'';
    $message1 .= '</table></div>';
    $message1 .= '</body></html>';
    mail("$admin_email", "Order #".$order, $message1, $headers);
    header("location:contact.php?sent=yes");
?>
lucke84
  • 4,516
  • 3
  • 37
  • 58

2 Answers2

0

Verify that php is installed on your friends server and that mail is enabled in your php.ini file

Columbus
  • 133
  • 1
  • 11
0

Check the Error Logs in cPanel for specific information. The error messages are descriptive enough to determine the errors without further investigation.

A 500 Internal Server Error can be caused by many things, including but not limited to invalid permissions, invalid ownership, bad lines in your php.ini or .htaccess file, invalid requests in the script, and others not mentioned here.

More often than not, this is not a problem with the server itself, and can be most often resolved by modifying something in your site's configuration.


Bad permissions, writeable by group

A bad permissions error may look something like this:

[Sun Jun 05 12:03:22 2012] [error] [client 00.000.00.00] SoftException in Application.cpp:601: Directory "/home/XXXXXXXXX/public_html/example.php" is writeable by group

In this instance the folder had permissions for a folder set too high. To correct this, the permissions need to be changed from "777" to "755".

Directories and folders should be 755. Executable scripts within the cgi-bin folder must be 755. Images, media, and text files like HTML should be 644.

Files - 644
CGI Scripts - 755
Directories - 755


Bad .htaccess, Invalid code, command, or syntax

In the .htaccess file, you may have added lines that have typos, are worded badly or conflicting. The best way to troubleshoot this is comment out the lines in the .htaccess.

You can comment out a line in the .htaccess by adding # to the beginning. It is advisable to save an original copy of any file before you make changes.


FollowSymlinks

This error looks like so:

[Fri Jun 28 12:07:10 2011] [alert] [client 00.000.000.000] /home1/XXXXXXXXXXXX/public_html/.htaccess: Option FollowSymlinks not allowed here

For this case, use a permitted directive--in this case use "SymlinksIfOwnerMatches" instead of "FollowSymlinks", or remove the line entirely.


mondieki
  • 1,771
  • 3
  • 16
  • 24