Hi,

I'm building a contact form with the code below:

<?php
$formMessage = "";
$senderName = "";
$senderEmail = "";
$senderMessage = "";

if ($_POST['username']) {*// If the form is trying to post value of username field

// Gather the posted form variables into local PHP variables
 $senderName = $_POST['username'];
$senderEmail = $_POST['email'];
$senderMessage = $_POST['msg'];
// Make sure certain vars are present or else we do not send email yet
if (!$senderName || !$senderEmail || !$senderMessage) {

$formMessage = "The form is incomplete, please fill in all fields.";

} else {*// Here is the section in which the email actually gets sent

// Run any filtering here
$senderName = strip_tags($senderName);
$senderName = stripslashes($senderName);
$senderEmail = strip_tags($senderEmail);
$senderEmail = stripslashes($senderEmail);
$senderMessage = strip_tags($senderMessage);
$senderMessage = stripslashes($senderMessage);
//*End Filtering
$to = "PUT_YOUR_EMAIL_ADDRESS_HERE";*********
$from = "contact@your_website_here.com";
$subject = "You have a message from your website";
// Begin Email Message Body
$message = "
$senderMessage

$senderName
$senderEmail
 ";
// Set headers configurations
$headers* = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text\r\n";
$headers .= "From: $from\r\n";
// Mail it now using PHP's mail function
mail($to, $subject, $message, $headers);
$formMessage = "Thanks, your message has been sent.";
$senderName = "";
$senderEmail = "";
$senderMessage = "";
} // close the else condition

} // close if (POST condition
?>
<html>
<head>
<title>Contact Form</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="contact.php">
<?php echo $formMessage; ?>
<br />
<br />
Your Name:<br />
<input name="username" type="text" id="username" size="36" maxlength="32" value="<?php echo $senderName; ?>" />
<br />
<br />
Your Email:
<br />
<input name="email" type="text" id="email" size="36" maxlength="32" value="<?php echo $senderEmail; ?>" />
<br />
<br />
Your Message:
<br />
<textarea name="msg" id="msg" cols="45" rows="5"><?php echo $senderMessage; ?></textarea>
<br />
<br />
<br />
<input type="submit" name="button" id="button" value="Send Now" />
</form>
</body>
</html>

When I run the script I get the following error:
Parse error: syntax error, unexpected T_STRING in /home/jacsau/public_html/test.php on line 9

I also have tried creating some other PHP scripts but the above error always comes up, except on a different line number. Can you please help me!

PS: I'm using a host that uses the cPanel control panel in case you needed to know.

    Welcome to PHPBuilder! When posting PHP code, please use the board's [noparse]

    ..

    [/noparse] bbcode tags as they make your code much easier to read and analyze.

    As for your error, take a look at the code snippet in your post above. Notice all of the *'s all over the place? These are special spaces (perhaps non-breaking spaces? I've never confirmed this...) that the board's software censored (which incidentally exposes this particular error quite clearly; I doubt you have an actual asterisk in your source code at those locations).

    Replace those characters with normal spaces.

      Write a Reply...