Need help. Unexpected ELSE

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]

No, you can’t.

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

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]

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

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!";

}
}
?>

Nevermind… Nailed it. Finally.

Thanks for all the help! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service