This page isn’t working -- HTTP ERROR 500

Status
Not open for further replies.

georgemw

New Member
Messages
8
Reaction score
0
Points
1
I am working on a contact page that contains a contact form that goes to a .php page. For some reason, I am getting that my main host cannot handle this request.

The page is http://georgem.x10host.com/capstone/contact.html

The code for the PHP page is:

<?php
if(isset($_POST['email'])){
// Here is the email to information
$email_to = "meehangeorge73@gmail.com";
$email_subject = "This is from your website contact form";
$email_from = "CareerLink of Lancaster County";

// Error Code
function died($error){
echo "We are sorry, but there are error(s) found with the form you submitted.";
echo "These error(s) appear below.<br /><br />";
echo $error. "<br /><br />";
echo "Please go back and fix these errors <br />";
die();
}

// Validation
if(!isset(_POST['name']) ||
!isset(_POST['email']) ||
!isset(_POST['subject']) ||
!isset(_POST['message'])){
died('We are sorry but there appears to be a problem with the form you submitted.');

}

// Variables
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// Expected Strings
$error_message ="";
$email_expect = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp, $email)){
$error_message .= 'The Email address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z.'-]+$/";
if(!preg_match($string_exp, $name)){
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
$$string_expt = "/^[A-Za-z0-9.'-]+$/";
if(!preg_match($string_expt, $subject)){
$error_message .= 'The Subject you entered does not appear to be valid.<br />';
}
if(strlen($message)<2){
$error_message .= 'The message you entered does not appear to be valid.<br />';
}
if(strlen($error_message)>0){
died($error_message);
}
$error_message = "Form Details Below.\n\n";

// Sanitization
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 .= "Subject:" . clean_string($subject) . "\n";
$email_message .= "Message:" . clean_string($message) . "\n";

// Create Email Headers
$headers = 'From: ' .$email_From . "\r\n". 'Reply-To:' .$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- Success Message Goes Here -->
Thank you for contacting us. We will be in touch with you shortly.<br />
Please cleck<a href="index.html">here</a> to go back to the home page.
<?php
}
?>

Any ideas what I am doing wrong will be greatly appreciated.
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
Any ideas what I am doing wrong will be greatly appreciated.
=
as a start - it looks like you are setting the from header to [ CareerLink of Lancaster County ]

$email_from = "CareerLink of Lancaster County"; ==> $headers = 'From: ' .$email_From
###
-
spoofing the [ From ] header is not allowed - Emails with the [ From ] header not set with a working Email address that exists and is actually part of your x10hosting's free-hosting account will be silently discarded - you will not receive any notice
###
-
some information...

The only setup to use the PHP mail() function is to have a valid Email address in your x10hosting's free-hosting account

external [ SMTP ] is blocked on x10hosting's free-hosting servers
all Email must go out through outbound spam filters on 10hosting's SMTP server - to be scanned for spam and phishing and other test - messages with no body content - and HTML-only mail (mail with no plain text part) - and messages with no subject - and messages that just say "Testing" (or like that) - and anything else that looks "spammy" (as far as the outbound mail filters are concerned) will be silently discarded - or sometimes the transfer to the SMTP server fails - you will not receive any notice when it fails
###
-
a check list...

1.> must have ASCII text in both subject and body
2.> messages that identify themselves as test messages are silently discarded
3.> messages that looks "spammy" - as far as the outbound mail filters are concerned - are silently discarded
4.> the FROM header must be a Email address that actually exists and is associated with your x10hosting's free-hosting account (is one you created - and NOT the senders Email address)
5.> Emails are not sent from the individual x10hosting's free-hosting servers - but are sent from a centralized outbound scanning SMTP server
6.> external [ SMTP ] is blocked - all Email must go out through outbound spam filters on 10hosting's SMTP server
###
 

georgemw

New Member
Messages
8
Reaction score
0
Points
1
Sorry bdistler, I should have done a bit more explaining, you see this site is for CareerLink of Lancaster County it is my service project for my Capstone class for Harrisburg Area Community College. The site needs to be finished by Friday and I spent most of the last three days working on trying to fix this and some other issues. The reason I put my email address in there is because I wanted to send a few test messages to make sure it work and I didn't want them going to the client's email and have her think I was spamming her. Once I am done with it I have to present it to the client and all parts have to be functional and I will be putting her email in to replace mine. That is why I put this request for help up. I didn't mean to make it look like I was trying to do something illegal, I am trying to make sure I pass the course.

I do appreciate your comments, I just have a few follow-up questions if you don't mind. To be honest, they don't have a PHP class at the college so I followed the code from a YouTube Video, so I do not understand what you meant in #1 of the checklist "must have ASCII text in both subject and body. Can you please elaborate?

As for the rest (2 thru 6), if I understand it right, I need to set up an email account with x10 hosting, replace that email with the one I have in the header (the Gmail email), that should take care of #5 and #6 and that should also take care of #2 and #3?

bdistler, again thank you so much for your help with this.

George
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
I do not understand what you meant in #1 of the checklist "must have ASCII
-
that is plan text - like "how high is the moon" - with no HTML code in it
###
-
I need to set up an email account with x10 hosting, replace that email with the one I have in the header (the Gmail email)
-
no issue with the gmail address

you are going the wrong way...

this is the line you need to replace [ CareerLink of Lancaster County ] inside the quotes with your x10hosting's Email address --> [ $email_from = "CareerLink of Lancaster County"; ]
###
-
this line should start with one [ $ ] not two --> [ $$string_expt = "/^[A-Za-z0-9.'-]+$/"; ]
###
-
this line should start with [ die ] not [ died ] --> [ died('We are sorry but there appears to be a problem with the form you submitted.'); ]
###
-
when testing add this line at the top of the file --> [ error_reporting(E_ALL); ] - right under the [ <?php ]
###
-
I will do some test of your code on my site to stop that error 500 - then post back here
###
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
to save time while debugging - I reformatted your code

it will not send a email yet

use cPanel's [ File Manager ] to test the 4 lines of $_POST near the top of the file

you can edit and save in a browser tab - with the [ File Manager ]
then run (by using reload) your test in a browser tab - with the test script
that way you do not need to upload the script for each test - and will save you time

I found that you can not have a space in the [ name ] and other errors

cut and paste this code into a file named [ test_code.php ] upload that file into folder [ public_html ]
run it with [ YourAccountDomain/test_code.php ]
-
PHP:
<?php
error_reporting(E_ALL);

/*** temp debug setting in $_POST ***/
$_POST['name'] = "Bad-Dog";
$_POST['email'] = "tester@bigsky.info";
$_POST['subject'] = "sky-Color";
$_POST['message'] = "it Is gReen and Red";


if(isset($_POST['email']))
  {
    // Here is the email to and from - information
    $email_to = "your@gmail.com";
    $email_subject = "This is from your website contact form";
    $email_from = "your@x10hosting";

    // Variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    //*** Functions start ***/

    // Error Code
    function died($error)
      {
        echo "We are sorry, but there are error(s) found with the form you submitted.";
        echo "These error(s) appear below.<br /><br />";
        echo $error. "<br /><br />";
        echo "Please go back and fix these errors <br />";
        die();
      }

    function clean_string($string)
      {
        // Sanitization
        $bad = array("content-type", "bcc", "to:", "cc:", "href");
        return str_replace($bad, "", $string);
      }

    //*** Functions end ***/

    //*** Validation start ***/

    if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['subject']) || !isset($_POST['message']))
      {
        die('We are sorry but there appears to be a problem with the form you submitted.');
      }

    // Expected Strings
    $error_message ="";

    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}$/';

    if(!preg_match($email_exp, $email))
      {
        $error_message .= 'The Email address you entered does not appear to be valid.<br />';
      }

    $string_exp = "/^[A-Za-z.'-]+$/";

    if(!preg_match($string_exp, $name))
      {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
      }

    $string_exp = "/^[A-Za-z0-9.'-]+$/";

    if(!preg_match($string_exp, $subject))
      {
        $error_message .= 'The Subject you entered does not appear to be valid.<br />';
      }

    if(strlen($message) < 2)
      {
        $error_message .= 'The message you entered does not appear to be valid.<br />';
      }

    if(strlen($error_message)>0)
      {
        died($error_message);
      }

    $email_message = "Name: " . clean_string($name) . "<br />\n";
    $email_message .= "Email: " . clean_string($email) . "<br />\n";
    $email_message .= "Subject: " . clean_string($subject) . "<br />\n";
    $email_message .= "Message: " . clean_string($message) . "<br />\n";

    //*** Validation end ***/

    // Create Email Headers
    $headers = 'From: ' . $email_from . "\r\n";
    $headers .= 'Reply-To:' . $email . "\r\n";

/*
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
*/
    // Success Message Goes Here
    echo "Thank you for contacting us. We will be in touch with you shortly.<br />";
//   Please cleck<a href="index.html">here</a> to go back to the home page."

print "<br />\n<br />\ntest print of \$email_message<br />\n==><br />\n" . $email_message . "<==<br />\n";
  }
?>
-


that is all for me tonight - more work on it tomorrow
***
 
Last edited:

georgemw

New Member
Messages
8
Reaction score
0
Points
1
Wow, thank you so much. I have been playing around with it and I got it to print but like you said I still get the error code when I go to use x-Mailer section. At least now I know where the issue is. I really appreciate all the help you are giving me here. I'll have to do some more research on PHP over the summer to get better at this.

I don't know how to get my code in a box like yours I used the code tags but this post became gibberish. so here is the code.
<?php
error_reporting(E_ALL);

if(isset($_POST['email']))
{
// Here is the email to and from - information
$email_to = "gmaseminars@gmail.com";
$email_subject = "This is from your website contact form";
$email_from = "mail@georgem.x10host.com";

// Variables
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

//*** Functions start ***/

// Error Code
function died($error)
{
echo "We are sorry, but there are error(s) found with the form you submitted.";
echo "These error(s) appear below.<br /><br />";
echo $error. "<br /><br />";
echo "Please go back and fix these errors <br />";
die();
}

function clean_string($string)
{
// Sanitization
$bad = array("content-type", "bcc", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}

//*** Functions end ***/

//*** Validation start ***/

if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['subject']) || !isset($_POST['message']))
{
die('We are sorry but there appears to be a problem with the form you submitted.');
}

// Expected Strings
$error_message ="";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp, $email))
{
$error_message .= 'The Email address you entered does not appear to be valid.<br />';
}

$string_exp = "/^[A-Za-z.'-]+$/";

if(!preg_match($string_exp, $name))
{
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}

//$string_exp = "/^[A-Za-z0-9.'-]+$/";

//if(!preg_match($string_exp, $subject))
// {
// $error_message .= 'The Subject you entered does not appear to be valid.<br />';
//}

if(strlen($message) < 2)
{
$error_message .= 'The message you entered does not appear to be valid.<br />';
}

if(strlen($error_message)>0)
{
died($error_message);
}

$email_message = "Name: " . clean_string($name) . "<br />\n";
$email_message .= "Email: " . clean_string($email) . "<br />\n";
$email_message .= "Subject: " . clean_string($subject) . "<br />\n";
$email_message .= "Message: " . clean_string($message) . "<br />\n";

//*** Validation end ***/

// Create Email Headers
$headers = 'From: ' .$email_from. "\r\n";
$headers .= 'Reply-To:' . $email . "\r\n";

// Modified the @mail to if (mail())but it didn't work either.
'X-Mailer: PHP/' . phpversion();
if(mail($email_to, $email_subject, $email_message, $headers));

// Success Message Goes Here
echo "Thank you for contacting us. We will be in touch with you shortly.<br />";
echo "<meta http-equiv='refresh' content=0;url=index.html">;

/*print "<br />\n<br />\ntest print of \$email_message<br />\n==><br />\n" . $email_message . "<==<br />\n";*/
}
?>
 
Last edited:

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
I still get the error code when I go to use x-Mailer section
-
you still have a lot of work to do on this script

try a name of "Bad Dog" (with a space in it)
###
-
I have tested your code - with this mod at the bottom -by sending Emails to my Gmail account and accounts on other host that I have - from my account on x10hosting's free-hosting server [ xo3 ]

to test sending Emails replace everything after this line --> [ // Create Email Headers ] with this code
PHP:
$headers = 'From: ' .$email_from. "\r\n";
$headers .= 'Reply-To:' . $email . "\r\n";
$headers .= 'Return-Path: ' . $email_from . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";

// temp output for debug
print "<pre>";
print "\$email_to ==>" . $email_to . "<==<br />\n";
print "\$email_subject ==>" . $email_subject . "<==<br />\n";
print "\$email_message ==v<br />" . $email_message . "^==<br />\n";
print "\$headers ==v<br />" . $headers . "^==<br />\n";
print "</pre>";

if(mail($email_to, $email_subject, $email_message, $headers))
  {
    // Success Message Goes Here
    echo "Thank you for contacting us. We will be in touch with you shortly.<br />";
  }
  else
    {
      died("there was some type of error while sending the Email");
    }
}
?>
-
post back when you can send Emails or you have issure doing so

after that I have some updates for the Validation block
###
 

georgemw

New Member
Messages
8
Reaction score
0
Points
1
Thanks again for your help I am learning a lot more from debugging this form than I would be sitting in a classroom listening to a professor read a powerpoint presentation. So, far the validations are kicking in stating that my name is wrong. For some reason, it isn't accepting capital letters and lowercase letters it only accepts lowercase letters. Again thanks for all your help.

Have a good day,
George
 

georgemw

New Member
Messages
8
Reaction score
0
Points
1
I got one email through before it stopped recognizing lowercase letter. So now it won't take anything as valid.
 

georgemw

New Member
Messages
8
Reaction score
0
Points
1
The only thing I made changes to was what you told me to change. When I tested it said that the name you entered does not appear to be valid. The regular error message. So, I tried using lowercase letters instead of capital letters for the first and last name (George Meehan). It worked. When I tried to do it again with a different address I got the same error message I then tried all capital letters and mixed again and nothing. Here is the validation code that is stopping it.

$string_exp = "/^[A-Za-z.'-]+$/";
if(!preg_match($string_exp,$name))
{
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}

I think I am going to move on with this and not worry about it working. I'll get a lesser grade and most likely the client won't accept it but it was worth the shot. Thanks again for all your help. I'm sorry to have you spend so much of your time on this.

George
 
Last edited:

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
the code I ask you to overlay at the bottom of the file - had nothing to do with that test

all it should do is - output some debug information - then send the Email

this is the string you just posted "/^[A-Za-z.'-]+$/" - and this is from your first post at the top of this thread "/^[A-Za-z.'-]+$/" they are the same

for now - until you can send Emails - do not put a space in the name - I have a fix for that and other codeing errors - but after you can send Emails

the script works for me - but you need to test your Email
-
###
 

georgemw

New Member
Messages
8
Reaction score
0
Points
1
OK, what I did was commented out the name validation and ran through about 4 or 5 emails with different names and emails worked fine.
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
about 4 or 5 emails with different names and emails worked fine.
-
great - getting Email to 'work' on a free-hosting host can be hard at times
###
-
now to fix those 'Validation' issues - I have rem out the old lines so you can see what I did

replace everything below this line --> [ //*** Validation start ***/ ] with this code ..
PHP:
    $error_message ="";

    if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['subject']) || !isset($_POST['message']))
      {
        $error_message .= 'We are sorry but there appears to be a problem with the form you submitted.<br />';
      }

    // Expected Strings

 // $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}$/';
    $email_exp = "/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i";

    if(!preg_match($email_exp, $email))
      {
        $error_message .= 'The Email address you entered does not appear to be valid.<br />';
      }

 // $string_exp = "/^[A-Za-z.'-]+$/";
    $string_exp = "/^[A-Za-z ][A-Za-z ]*$/";

    if(!preg_match($string_exp, $name))
      {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
      }

//  $string_exp = "/^[A-Za-z0-9.'-]+$/";
    $string_exp = "/^[A-Za-z0-9.'\- ][A-Za-z0-9.'\- ]+$/";

    if(!preg_match($string_exp, $subject))
      {
        $error_message .= 'The Subject you entered does not appear to be valid.<br />';
      }

    if(!preg_match($string_exp, $subject) || (strlen(trim($message)) < 2))
      {
        $error_message .= 'The message you entered does not appear to be valid.<br />';
      }

    if(strlen($error_message)>0)
      {
        died($error_message);
      }

    $email_message = "Name: " . clean_string($name) . "<br />\n";
    $email_message .= "Email: " . clean_string($email) . "<br />\n";
    $email_message .= "Subject: " . clean_string($subject) . "<br />\n";
    $email_message .= "Message: " . clean_string($message) . "<br />\n";

    //*** Validation end ***/

    // Create Email Headers

    $headers = 'From: ' .$email_from. "\r\n";
    $headers .= 'Reply-To:' . $email . "\r\n";
    $headers .= 'Return-Path: ' . $email_from . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";

// temp output for debug
print "<pre>";
print "\$email_to ==>" . $email_to . "<==<br />\n";
print "\$email_subject ==>" . $email_subject . "<==<br />\n";
print "\$email_message ==v<br />" . $email_message . "^==<br />\n";
print "\$headers ==v<br />" . $headers . "^==<br />\n";
print "</pre>";

if(mail($email_to, $email_subject, $email_message, $headers))
  {
    // Success Message Goes Here
    echo "Thank you for contacting us. We will be in touch with you shortly.<br />";
  }
  else
    {
      died("there was some type of error while sending the Email");
    }
}
?>

###
 

georgemw

New Member
Messages
8
Reaction score
0
Points
1
Everything is working great now bdistler. Again I cannot thank you enough. I really appreciate all the help you gave me.
 

debo

New Member
Messages
8
Reaction score
0
Points
1
Thank you both here for this topic, it helped me too to have the contact form working.
Just 1 question, how to let it open a "thank you" (instead of the plain white page) page after submitting?
 
Status
Not open for further replies.
Top