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 = "[email protected]"; 
$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
https://forums.phpfreaks.com/topic/256771-else/
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 = "[email protected]"; 
$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
https://forums.phpfreaks.com/topic/256771-else/#findComment-1316350
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 = "[email protected]"; 
$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
https://forums.phpfreaks.com/topic/256771-else/#findComment-1316354
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
https://forums.phpfreaks.com/topic/256771-else/#findComment-1316359
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.