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");
?>