Can't get PHP mail() function to work


This is my code


Parse error: syntax error, unexpected ‘mail’ (T_STRING) in /storage/ssd5/582/2185582/public_html/email.php on line 21

Line 21 is the code above. Not sure what is wrong. I followed a tutorial step by step, and I’m just getting this error.


Can you link the tutorial that you are using? Maybe it has a syntax error. Or could you try setting the PHP version to 5.6?


I will changed it to 5.6 and test. I was using php 5.5


Oh ok. In that case, can you try using PHP version 7.1? Maybe this tutorial is using updated functions (don’t quote me on that, still learning too).


Even on 7.1 I’m getting the same exact error. Is it something with 000webhost not allowing this?

Here is all my code:


if(empty($name) || empty($email) || empty($msg)){
Print “All fields are required to send email”;
$email_from = $email;
$email_subject = “Email from”;
$email_body = “You have recieved a new message from $name. \n”.
“Here is the message: \n $msg”;
$to =""
Print"Email sent. Thank you for contacting UWRF Intervarsity!";


000webhost allows mail(), it should work perfectly. If we were having an issue, you’d get a different error. This has something to do with the syntax… maybe @ckhawand or @NGiNX can look at it when they are available?


Okay good to know. Then it probably is a syntax error in my php somewhere.


Hi @stevenhayes97!

You have forgotten a semicolon on line 12: $to =""


Thank you so much! It works now!


You’re welcome! :wink: