0

I am currently going through elithecomputerguy's youtube playlist for php programming. I am on part 7 of his 11 part series, this section talks about sending email with php. He writes out all the php code on notepad++ and uploads it to a standard godaddy web hosting account. I am using the same exact method, copying his code line by line, setting up the files in the same location and when I upload my email_form.php, it displays correctly

<HTML>
<HEAD>
</HEAD>
<BODY>

<form action="email_script.php" method="POST">

<p>Email Address: <input type="text" name="email" size="30"></p>

<p>Subject: <input type="text" name="subject" size="30"></p>

<p>Message: </p>
<p><textarea rows="10" cols="20" name="message"></textarea></p>

<input type="submit" name="submit" value="Submit">

</BODY>

</HTML>

Now I uploaded my email_script.php file just fine and it looks like so:

<?PHP

$from="test@mikesmtgadvice.com";
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];

mail($email, $subject, $message,"From:".$from);

print "Your message has been sent: </br?$email</br>$subject</br>$message</p>

?>

so when I go to mysite.com/test/email_form.php, it works and displays this form the way it should. However, when I fill in the form and hit submit, when it tries running the script, I get an 500 Internal Server Error. I have no idea where to look for this error and cannot find the error log, and therefore cannot figure this out. In the video, he does this exact same process and it works, is there a setting I need to change in my server or?

Thank you for your help in advance, I'm sorry for the long winded version but I wanted to be as specific as possible.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Mkk1009
  • 3
  • 1
  • 3
    Missing quote (and semi-colon) in `print "Your message has been sent: $subject$message` do `print "Your message has been sent: $subject$message";` – Funk Forty Niner Aug 20 '14 at 19:49
  • Try adding a try/catch block to your code, to see what the error is. – steinmas Aug 20 '14 at 19:49
  • Your script is insecure as it can be abuse byattackers to send SPAM (see header splitting). – MrTux Aug 20 '14 at 19:50
  • OK, I will look up on that and try it out, thank you. – Mkk1009 Aug 20 '14 at 19:58
  • [`You're welcome`](http://stackoverflow.com/questions/25413238/php-scripts-not-running-on-my-website#comment39642281_25413238) 11 mins. ago. – Funk Forty Niner Aug 20 '14 at 20:00
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – IMSoP Aug 20 '14 at 20:01
  • Is header splitting a method to circumvent these attacks or just the process they exploit to conduct the attack? I'm so new to this and would really prefer to get it right from the beginning. – Mkk1009 Aug 20 '14 at 20:06
  • @Mkk1009 - you should try to avoid putting user-generated content in the headers if you can. If the user sends specifically formatted text - by adding a linebreak in the middle - then anything after that linebreak will also be added to the headers - so they can add BCC lines, for example. If you do need to add user-generated content, then be sure to sanitize it, and make sure only the right kind of data is added - if it's supposed to be an email address, validate that the content looks like an email address – andrewsi Aug 21 '14 at 00:24

1 Answers1

0

You are missing a double quote and ; at the end of the print statement:

print "Your message has been sent: <br />$email<br />$subject<br />$message</p>";

Replace that with your print line and it will fix it.

Mic1780
  • 1,774
  • 9
  • 23
  • oh wow, I feel really dumb now lol, no kidding on one stupid mistake and nothing will work, and I managed two. Thank you very much! – Mkk1009 Aug 20 '14 at 20:01
  • Good luck on the rest of your tutorials. Also note that if you have access to php on a command line you can do a syntax check on a file by doing the following command: `php -l filename.php`. The `-l` argument means check for syntax errors. If there is one it will tell you where. – Mic1780 Aug 20 '14 at 20:06
  • Thank you, and do I need php installed on my computer to access it from the command line? – Mkk1009 Aug 20 '14 at 20:08
  • If you have something like WAMP or any version of PHP on your machine, all you have to do is add the path to your system path the directory where php is and you have access to php via command line: my path is `C:\wamp\bin\php\php5.3.13` and that directory contains my php.exe used for the mentioned command. – Mic1780 Aug 20 '14 at 20:11