Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Pear邮件()上添加重定向_Php - Fatal编程技术网

Php 在Pear邮件()上添加重定向

Php 在Pear邮件()上添加重定向,php,Php,到目前为止,邮件发送的信息都是正确的。我正在尝试将mail.php重定向到thank.php。它最终显示标题(“位置:) <?php if(isset($_POST['email'])) { require_once "Mail.php"; //PEAR mail is already installed in our current environment $email_to = "email@domain.com"; //Enter the email you want

到目前为止,邮件发送的信息都是正确的。我正在尝试将mail.php重定向到thank.php。它最终显示标题(“位置:)


    <?php

if(isset($_POST['email'])) {
require_once "Mail.php"; //PEAR mail is already installed in our current environment

$email_to = "email@domain.com";  //Enter the email you want to send the form to
$email_subject = "Subject";  // You can put whatever subject here

$host = "subdomain.domain.com";  // The hostname of your mail server
// If your email is with HostMySite, use the actual hostname of your mail server, for example:
//   SmarterMail: mailXX.safesecureweb.com OR win-mailXX.hostmanagement.net
//   OpenX-change: smtp.hostmanagement.net
// Contact Support if you aren't sure what to enter here.

$username = "email@domain.com";  // A valid email address you have setup 
$from_address = "email@domain.com";  // If your mail is hosted with HostMySite this has to match the email address above 
$password = "p4ssw0rd";  // Password for the above email address
$reply_to = "email@outlook.com";  //Enter the email you want customers to reply to
$port = "587"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with HostMySite

function died($error) {
// your error code can go here 
echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
echo "These errors appear below.<br /><br />"; 
echo $error."<br /><br />"; 
echo "Please go back and fix these errors.<br /><br />";
die();
}

// Validate expected data exists
if(!isset($_POST['salutation']) || !isset($_POST['fname']) || !isset($_POST['lname']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$salutation = $_POST['salutation']; // required
$first_name = $_POST['fname']; // required 
$last_name = $_POST['lname']; // required 
$email_from = $_POST['email']; // required 
$phone = $_POST['phone']; // required 
$message = $_POST['message']; // required 
$error_message = ""; 
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
} 
$string_exp = "/^[A-Za-z .'-]+$/"; 
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
} 
if(strlen($message) < 2) {
$error_message .= 'The message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Salutation: ".clean_string($salutation)."\n";
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n"; 
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Message: ".clean_string($message)."\n";

// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password, 'port' => $port);
$headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);

// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email_to, $headers, $email_message);

if (PEAR::isError($mail)) {?>
<!– include your own failure message html here –>
  Unfortunately, the message could not be sent at this time. Please try again later.

<!– Uncomment the line below to see errors with sending the message –>
<!– <?php echo("<p>". $mail->getMessage()."</p>"); ?> –>

<?php } else { ?>

<!– include your own success message html here –>

    header("Location: http://www.example.com/thank.php");

<?php } } ?>