Im having some confusion with a PHP and HTML code. I have this PHP code on an HTML website page. I was excited to discover I could use HTML code under the part that says echo to tell the user that the message has sent. If I only put HTML in the echo part (as seen below) the page works fine.
<?php
if ( isset( $_POST[ 'submit' ] ) ) {
$firstname = $_POST[ 'firstname' ];
$lastname = $_POST[ 'lastname' ];
$phone = $_POST[ 'phone' ];
$mailFrom = $_POST[ 'mail' ];
$message = $_POST[ 'message' ];
$mailTo = "abc@abc.com";
$headers = "From: " . $mailFrom;
$subject = "You have received an e-mail from your web site";
$message = "First Name: " . $firstname . " Last Name: " . $lastname . "\r\nPhone: " . $phone . "\r\nemail: " . $mailFrom . "\r\nMessage: " . $message;
If( mail( $mailTo, $subject, $message, $headers ) ) {
echo( "<h1>Message Sent</h1>
<p>Thank you for contacting us.Your message has been sent successfully and we will get back to you a soon as possible</p>" );
}
else {
echo( "We're sorry your message did not go through. Please return to our contact page and try again." );
}
}
?>
However if I put some HTML code in the section of else{ echo() } then it fails all together. No matter if the user does or does not fill out all the contact form information it gives the user an error 500.
<?php
if ( isset( $_POST[ 'submit' ] ) ) {
$firstname = $_POST[ 'firstname' ];
$lastname = $_POST[ 'lastname' ];
$phone = $_POST[ 'phone' ];
$mailFrom = $_POST[ 'mail' ];
$message = $_POST[ 'message' ];
$mailTo = "abc@abc.com";
$headers = "From: " . $mailFrom;
$subject = "You have received an e-mail from your web site";
$message = "First Name: " . $firstname . " Last Name: " . $lastname . "\r\nPhone: " . $phone . "\r\nemail: " . $mailFrom . "\r\nMessage: " . $message;
If( mail( $mailTo, $subject, $message, $headers ) ) {
echo( "<h1>Message Sent</h1>
<p>Thank you for contacting us.Your message has been sent successfully and we will get back to you a soon as possible</p>" );
}
else {
echo( "<h1>Message Sent</h1>
<p>We're sorry your message did not go through. Please return to our <a href="contact.html" contact page</a> and try again.</p>" );
}
}
?>
Does anyone know how I can make this work. Thank You
Aucun commentaire:
Enregistrer un commentaire