<?php
// Define some constants
define( "RECIPIENT_NAME", "John Smith" );
define( "RECIPIENT_EMAIL", "john@example.com" );
define( "EMAIL_SUBJECT", "Visitor Message" );
// Read the form values
$success = false;
$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
// If all values exist, send the email
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
}
// Return an appropriate response to the browser
if ( isset($_GET["ajax"]) ) {
echo $success ? "success" : "error";
} else {
?>
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?>
<?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>
<p>Click your browser's Back button to return to the page.</p>
</body>
</html>
<?php
}
?>
Ok, so this is the code that i am using to send mail. I have contact.html and form that uses this php script. I would like this script to go to or redirect to some page (eg. contact_success.html) if success or go to another page if error (contact_error.html). Thanks
if ($success) {
header("Location: /success.html");
exit;
} else {
header("Location: /error.html");
exit;
}
if($success) {
header('location:contact_success.html');
}
else {
header('location:contact_error.html');
}
try this code
if ($success == 'success') {
header("Location: success.html");
exit;
} else {
header("Location: error.html");
exit;
}
This is very basic information on what I think you are trying to do. It redirects to a url after form is submitted.
<?php
$goto_after_mail = "http://www.domain.com"; // This is the URL that is shown after the mail is submitted.
$from_mail = $_REQUEST['email']; // Be sure your EMAIL form field is identified as "email".
$from_name = $_REQUEST['name']; // Be sure your NAME form field is identified as "name".
$header = "From: \\"$from_name\\" <$from_mail>\\
";
$header .= "MIME-Version: 1.0\\
";
$header .= "Content-Type: text/plain; charset=\\"utf-8\\"\\
";
$header .= "Content-Transfer-Encoding: 7bit\\
";
$subject = "Your Message Subject"; // Insert your message subject.
foreach ($_REQUEST as $key => $val) {
if ($key != "" && $key != "") {
$body .= $key . " : " . $val . "\\
";
}
}
if (mail("mail@domain.com", $subject, $body, $header)) { // Insert your e-mail address to be used to view your submissions.
header("Location: ".$goto_after_mail);
}
?>
Although this is basic, you should be able to read the code and get the idea.
Regards, Tom
Very nice. Here's to add to your sendmail script with proper redirection after checking the actual completion of the mail function.
Hope this is helpful!
//Email Notification
// the message
$msg = $today." : A NEW Message.
\Property: ".$property."\Value: ".$Value."
";
// use wordwrap() if lines are longer than 70 characters
// we'll use base 64 if needed with the later email templates
$msg = wordwrap($msg,70);
// old send email
//mail("someemail@gmail.com,info@somedomain.com","some Message",$msg);
// Redirect after the mail is sent so they are not blank
if (mail("someemail@address.com"," - A New item has posted",$msg)){
// To redirect form on a particular page
header("Location: http://google.com");
}