Hello, I'm completely new at PHP. I've been looking at some tutorials on youtube (phpacademy is wonderful), and been reading about different functions and operators of php online over the past couple of days.
I'm definitley not an expert and probably won't understand if you use very technical terms when trying to answer the question I have for you lol.
I am a teacher and I want to put a contact form on my website that the students can use to email me. I have several requirements in the form they type into, unfortunatley the php can't even make it through the code without giving me an error.
It only makes it to line 17 before it hits this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/a9896735/public_html/recieve_email.php on line 17
I'm thinking it's because there's something I'm not understanding in how you are supposed to format your syntax when concatenating variables.
Anyways here's my code, can anyone have a look and see if you can get this newbie back on track??
<?php
if (isset($_POST['submit']))
{
//get data from form
$fname = $POST['firstname'];
$lname = $POST['lastname'];
$useremail = $POST['useremail'];
$message = $POST['message'];
$classperiod = $_POST['classperiod'];
include("my_chem_site.php");
include("my_email.php");
$from = $website.''.$fname.''.$lname.';
$subject = "Email from $website";
$message = "A new email has been sent by $useremail.' '.$fname.' '.$lname.' '.$classperiod.'!' \n
Message: \n\n $message \n\n
Details: \n
Name: $fname.''.$lname. \n
Email Address: $useremail \n
Class Period: $classperiod \n";
//End of Message
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
$return = "recieve_email.php";
if ($fname)
{
if ($lname)
{
if ($useremail)
{
if ($message)
{
if (classperiod)
{
$namelen = 30;
$messagelen = 500;
$periodlen = 1;
if (strlen($fname)>=1&&($fname)<=$namelen&&strlen($lname)>=1&&($lname)<=$namelen&&strlen($message)<=$messagelen&&strlen($classperiod)=$periodlen) //length check
{
mail($to, $subject, $message, $headers);
echo "Thank you! Your mail has been sent!";
echo '<meta http-equiv="refresh" content="2; $return" />';
}
else
{
echo "Either the name field(s) are too long or the message body is too long, or you have not entered your class period. You are allowed $namelen characters for the name and $messagelen for the message. You must also enter your class period.";
echo '<meta http-equiv="refresh" content="2; $return" />';
}
}
else
{
echo "You must enter a message to be sent";
echo '<meta http-equiv="refresh" content="2; $return" />';
}
}
else
{
echo "You must enter an email address";
echo '<meta http-equiv="refresh" content="2; $return" />';
}
}
else
{
echo "You must enter your first and last name!";
echo '<meta http-equiv="refresh" content="2; $return" />';
}
}
}
else
{
?>
<form action="recieve_email.php" method="POST" style="font-family: Comic Sans MS">
<p align="left">First name: <input type="text" name="firstname" /><br /><br />
Last name: <input type="text" name="lastname" /><br /><br />
Email: <input type="text" name="useremail" /><p align="left">
Class Period <input type="text" name="classperiod" size="20"><br /><br />
Message:<br>
<textarea name="message" rows="8" cols="58"></textarea><br /><br />
<table align="center"><tr><td><input type="submit" name="submit" value="Send me an Email" style="font-family: Comic Sans MS" />
<input type="reset" value="Start Over" style="font-family: Comic Sans MS" /></td></tr></table></p>
</form>
<p><b>
<font face="Comic Sans MS" size="2" color="Black">
All fields denoted with an * are required</font></b>
</p>
<?php
}
?>
Thanks for any help you can give me!!