Hi I got some codes on this site for creating a PHP form plus getting the response message on the same page. Everything about the response works great but when I submit the message I only get the failure response, I will place the codes here so maybe someone can point out a mistake.
sendEmail.php:
<?php
/* Configuration */
$subject = 'Contacto Nebraska Web'; // Set email subject line here
$mailto = 'info@nebraskafilms.com.ar'; // Email address to send the form to
/* END Configuration */
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$timestamp = date("F jS Y, h:iA.", time());
// HTML for email to send submission details
$body = "
<br>
<p>Message:</p>
<p><b>Name</b>: $name <br>
<b>Email</b>: $email<br>
<p>This form was submitted on <b>$timestamp</b></p>
";
// Success Message
$success = "
<div class=\"row\">
<div class=\"thankyou\">
<h3>Submission successful</h3>
<p>Mensaje recibido, gracias por contactarte con Nebraska Films, te responderemos a la brevedad.</p>
</div>
</div>
";
$headers = "From: $name <$email> \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>$body</body></html>";
if (mail($mailto, $subject, $message, $headers)) {
echo "$success"; // success
} else {
echo 'Hubo un error, por favor intenta nuevamente.'; // failure
}
?>
I also have another form that works perfectly and I get the emails but with this one I can’t get the response message on the same page, it takes me to a blank page with unformatted text. Here is the other PHP code:
<?php
// Replace this with your own email address
$siteOwnersEmail = 'info@nebraskafilms.com.ar';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Por favor ingresá tu nombre.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Por favor ingresá un email válido.";
}
// Check Message
if (strlen($contact_message) < 10) {
$error['message'] = "Por favor ingresá tu mensaje. Debe contener 10 caracteres como mínimo.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set(sendmail_from,'info@nebraskafilms.com.ar'); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "Tu mensaje fue enviado correctamente."; }
else { echo "Hubo un error. Por favor intente de nuevo."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
Thanks Ryan, I replaced all the “contact” id with “contactForm” but the SEND button remains the same. Here is a link to the site with the contact form at the bottom: http://nebraskafilms.com.ar/