Jump to content

else


ecabrera

Recommended Posts

how come the the else donest not work it shows up "Please enter your feedback or insert your email"

 

<form method="post" action="feedback.php">
Email: <input name="email" type="text"><br> 
Feedback:<br><textarea name="message" rows="15" cols="40">
</textarea>
<br> <input type="submit" name="sendbtn" value="Send" />
</form>

<?php

$to = "ecabrera9@ymail.com"; 
$subject = "Feedback";
$email = $_POST['email']; 
$message = $_POST['message'];
$headers = "From: $email"; 

if($_POST['sendbtn']){

if($email && $message)
$sent = mail($to, $subject, $message, $headers);
echo "Thank you for the feedback. We will be in touch with you very soon.";
}else{
echo "Please enter your feedback or insert your email";
}

?>

Link to comment
Share on other sites

try the following to see what was actually entered in the fields.

<form method="post" action="feedback.php">
Email: <input name="email" type="text"><br> 
Feedback:<br><textarea name="message" rows="15" cols="40">
</textarea>
<br> <input type="submit" name="sendbtn" value="Send" />
</form>

<?php

$to = "ecabrera9@ymail.com"; 
$subject = "Feedback";
$email = $_POST['email'];
$message = $_POST['message'];



echo("email = '".$email."'<br />");
echo("message = '".$message."'<br />");




$headers = "From: $email"; 

if($_POST['sendbtn']){

if($email && $message)
$sent = mail($to, $subject, $message, $headers);
echo "Thank you for the feedback. We will be in touch with you very soon.";
}else{
echo "Please enter your feedback or insert your email";
}

?>

 

if any the content of the fields will be echod between the two sets of single quotes.

Link to comment
Share on other sites

try this

 

<form method="post" action="feedback.php">
Email: <input name="email" type="text"><br> 
Feedback:<br><textarea name="message" rows="15" cols="40">
</textarea>
<br> <input type="submit" name="sendbtn" value="Send" />
</form>

<?php

$to = "ecabrera9@ymail.com"; 
$subject = "Feedback";
$email = $_POST['email']; 
$message = $_POST['message'];
$headers = "From: $email"; 

if($_POST['sendbtn']){

if($email && $message){
$sent = mail($to, $subject, $message, $headers);
echo "Thank you for the feedback. We will be in touch with you very soon.";
}else{
echo "Please enter your feedback or insert your email";
}
}

Link to comment
Share on other sites

the mail function returns true or false depending on success or failure, you can capture that with the $sent = bit, you dont Have to do it.

 

you could also do this way:

if($email && $message ){
if (mail($to, $subject, $message, $headers))
{
echo "Thank you for the feedback. We will be in touch with you very soon.";
}
else
{
echo 'unable to send email';
}

}else{
echo "Please enter your feedback or insert your email";
}
}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.