0

Just trying to get a very simple form working
Getting a
Parse error: syntax error, unexpected T_IS_EQUAL on line 10

<?php
$to = "";
$subject = "Contact Us";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$embody = "Name: $name\nEmail: $email\nSuggestion: $message" ;
$sent = mail($to, $subject, $embody, $headers) ;
if($name || $email || $message) == "" {
	echo "You seem to have left something out. Please fill in all the fields and try again.<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
else
if($sent)
	{echo "Thank you $name, your mail has been sent successfully with the message of:<br /><br /><i>$message</i><br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
else
	{echo "We encountered an error sending your mail<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
?>

I know its something with the checking if the fields are blank, but I can't find what
Thanks

Edited by Mouse1989: n/a

3
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by Jerail
0

Just trying to get a very simple form working
Getting a
Parse error: syntax error, unexpected T_IS_EQUAL on line 10

<?php
$to = "";
$subject = "Contact Us";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$embody = "Name: $name\nEmail: $email\nSuggestion: $message" ;
$sent = mail($to, $subject, $embody, $headers) ;
if($name || $email || $message) == "" {
	echo "You seem to have left something out. Please fill in all the fields and try again.<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
else
if($sent)
	{echo "Thank you $name, your mail has been sent successfully with the message of:<br /><br /><i>$message</i><br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
else
	{echo "We encountered an error sending your mail<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
?>

I know its something with the checking if the fields are blank, but I can't find what
Thanks

In the above code you forgot to put

braces for the if statement, try the following

if(($name || $email || $message) == "")


Thanks & Regards
Sai Prem
<snipped>

Edited by nav33n: Fake signature snipped. Use Control Panel -&gt; Edit Signature to add a signature.

0

In the above code you forgot to put

braces for the if statement, try the following

if(($name || $email || $message) == "")

That fixed the error, but now I am getting the "You seem to have left something out. P..." all the time even when everything is filled in.

0

If you are doing it from local environment, the mail sending will not works for you. You need to set the smtp address and port number in the php.ini file

Edited by saiprem: Fake signature snipped.

0

It all works fine and I get the form mail through to my email inbox. Everything is ok, I just wish to check the boxes are not blank

0

Try changing if($name || $email || $message) == "" to if(empty($name)||empty($mail)||empty($message)) { } The preferred method of checking whether or not a variable is empty is with the empty() function ( [i]bool[/i] [b]empty[/b] ( [i]mixed[/i] $var ) ).
The OR operator (||) doesn't work quite the way you used it above.
You also left out a closing bracket.

Edited by Jerail: n/a

0
<form method="post" action="contact.php" onsubmit="window.open('contact.php','popup','width=200,height=200,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">
        Name: <input name="name" type="text" maxlength="15" value="">
        <br />
Email:&nbsp;&nbsp;<input name="email" type="text" maxlength="50"  value="">
<br />
Suggestion:<br />
<textarea name="message" rows="5" cols="40"  value=""></textarea>
<br>
<input type="submit" value="Submit"><input type="reset" value="Reset">
	    </form>
$to = "email ommitted";
$subject = "Contact Us";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$embody = "Name: $name\nEmail: $email\nSuggestion: $message" ;
$sent = mail($to, $subject, $embody, $headers) ;
if(empty($name)||empty($mail)||empty($message))  {
	echo "You seem to have left something out. Please fill in all the fields and try again.<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
else 
if($sent)
	{echo "Thank you $name, your mail has been sent successfully with the message of:<br /><br /><i>$message</i><br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
else
	{echo "We encountered an error sending your mail<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
?>

Still same problem :/ get blank error even when all boxes are filled, forgot to add the HTML form before. Possible conflict with value=""?

Edited by Mouse1989: n/a

0

Yes you should not use value="" in your source, and more over the default will be null, it is not necessary to put that, remove that and retry again

0

Change empty($mail) to empty($email) There's a discrepancy between your variables. $mail does not exist.
Also, you should really do your validation before sending the e-mail with mail(). This would avoid a lot of unnecessary blank e-mails being sent.

Also, do what saiprem said and remove the value = "" attributes from your HTML form. value isn't even a valid attribute of <textarea> .

Edited by Jerail: n/a

0

Thanks for the discrepancy note

How would I go about doing validation beforehand?

Edited by Mouse1989: n/a

0

Well, you have your mail() function before the if(empty) functions. What you should really do is:

if(empty($email)...etc...) {
    echo "error";
}
else {
    mail($to,$etc);
    echo "success";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.