Need help. Unexpected ELSE


#1

not sure if I can use 2 else’s in a row, i’m basically just trying to make sure the var $email contains . and @

[php]<?php
$action=$_REQUEST[‘action’];
if ($action=="") /* display the contact form /
{
?>


Your name:



Your email:



Your message:





<?php
}
else /
send the submitted data */
{
$name=$_REQUEST[‘name’];
$email=$_REQUEST[‘email’];
$message=$_REQUEST[‘message’];
function testEmail($email) {
if (preg_match ( “/.|@/”, $email))
else
echo “Email not OK”;
if (($name=="")||($message==""))
{
echo “All fields are required, please fill <a href=”">the form again.";
}
else{
$from=“From: $name<$email>\r\nReturn-path: $email”;
$subject=“Message sent using your contact form”;
mail(“contact[member=88428]kznow[/member].org”, $subject, $message, $from);
echo “Email sent!”;
}
}
?>[/php]


#2

No, you can’t.

[php]if(!filter_var($_POST[‘email’], FILTER_VALIDATE_EMAIL) ) echo “Your email is bad.”;[/php]


#3

is this what it’s supposed to look like? if so it contains one too many {

[php]<?php
$action=$_REQUEST[‘action’];
if ($action=="") /* display the contact form /
{
?>


Your name:



Your email:



Your message:





<?php
}
else /
send the submitted data */
{
$name=$_REQUEST[‘name’];
$email=$_REQUEST[‘email’];
$message=$_REQUEST[‘message’];
function testEmail($email) {
if(!filter_var($_POST[‘email’], FILTER_VALIDATE_EMAIL) ) echo “Your email is bad.”;
if (($name=="")||($message==""))
{
echo “All fields are required, please fill <a href=”">the form again.";
}
else{
$from=“From: $name<$email>\r\nReturn-path: $email”;
$subject=“Message sent using your contact form”;
mail(“contact[member=88428]kznow[/member].org”, $subject, $message, $from);
echo “Email sent!”;
}
}
?>[/php]


#4

You are defining a function inside of the if block. Why?


#5

OK, I took the function out, now it’s totally messed up, it says bad email when I use a bad email, and then it also says ‘email sent’ and sends it with no email defined.

I’m confused.

I think I nailed it now though… this seems to work… kinda… if I leave name or message blank it says
All fields are required, please fill the form again.Email sent!
and it sends the email with blank fields.

The email check part seems to work though

<?php $action=$_REQUEST['action']; if ($action=="") /* display the contact form */ { ?>
  <form  action="" method="POST" enctype="multipart/form-data">
  <input type="hidden" name="action" value="submit">
  Your name:<br>
  <input name="name" type="text" value="" size="30"/><br>
 Your email:<br>
 <input name="email" type="text" value="" size="30"/><br>
 Your message:<br>
 <textarea name="message" rows="7" cols="30"></textarea><br>
 <input type="submit" value="Send email"/>
 </form>
 <?php
 } 

else /* send the submitted data */
{
$name=$_REQUEST[‘name’];
$email=$_REQUEST[‘email’];
$message=$_REQUEST[‘message’];

 if (($name=="")||($message=="")) echo "All fields are required, please fill <a href=\"\">the form</a> again.";
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) echo "Your email is bad";
 else{       
     $from="From: $name<$email>\r\nReturn-path: $email";
     $subject="Message sent using your contact form";
     mail("contact[member=88428]kznow[/member].org", $subject, $message, $from);
     echo "Email sent!";

}
}
?>


#6

Nevermind… Nailed it. Finally.

Thanks for all the help! :slight_smile: