我正在尝试将联系表单与thankyouurl.php相关联,以便在发送电子邮件后显示自定义页面。一切都在代码中工作,除了那一点。我尝试了一些不同的东西,但PHP不是我强大的一面。
<?php
@ini_set('display_errors', 0);
@ini_set('track_errors', 0);
@date_default_timezone_set('Europe/Bucharest'); // Used only to avoid annoying warnings.
if($_REQUEST['action'] = 'email_send') {
$array['name'] = isset($_REQUEST['name']) ? strip_tags(trim($_REQUEST['name'])) : '';
$array['email'] = isset($_REQUEST['email']) ? ckmail($_REQUEST['email']) : '';
$array['subject'] = isset($_REQUEST['subject']) ? strip_tags(trim($_REQUEST['subject'])) : '-';
$array['message'] = isset($_REQUEST['message']) ? (trim(strip_tags($_REQUEST['message'], '<b><a><strong>'))) : '';
// Visitor IP:
$ip = ip();
// DATE
$date = date('l, d F Y , H:i:s');
// BEGIN
require('config.inc.php');
require('phpmailer/5.1/class.phpmailer.php');
$m = new PHPMailer();
$m->IsSMTP();
$m->SMTPDebug = false; // enables SMTP debug information (for testing) [default: 2]
$m->SMTPAuth = true; // enable SMTP authentication
$m->Host = $config['smtp_host']; // sets the SMTP server
$m->Port = $config['smtp_port']; // set the SMTP port for the GMAIL server
$m->Username = $config['smtp_user']; // SMTP account username
$m->Password = $config['smtp_pass']; // SMTP account password
$m->SingleTo = true;
$m->CharSet = "UTF-8";
$m->Subject = ($array['subject'] == '-') ? $config['subject'] : $array['subject'];
$m->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$m->AddAddress($config['send_to'], 'Contact Form');
$m->AddReplyTo($array['email'], $array['name']);
$m->SetFrom($config['smtp_user'], 'Contact Form');
$m->MsgHTML("
<b>Date:</b> {$date} <br>
<b>Name:</b> {$array['name']}<br>
<b>Email:</b> {$array['email']}<br>
<b>Subject:</b> {$array['subject']}<br>
<b>Message:</b> {$array['message']}<br>
---------------------------------------------------<br>
IP: {$ip}
");
if($config['smtp_ssl'] === true)
$m->SMTPSecure = 'ssl'; // sets the prefix to the server
// @SEND MAIL
if($m->Send()) {
header( "http://xyz.ie/thankyouurl.php" );
}
else
{
header( "http://xyz.ie/errorurl.php" );
}
function ip() {
if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }
elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); }
elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); }
elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); }
elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); }
else { $ip = $_SERVER['REMOTE_ADDR']; }
return $ip;
}?>
答案 0 :(得分:1)
使用标头位置重定向到其他页面:
header("Location: http://xyz.ie/thankyouurl.php");
所以改变你的代码:
// @SEND MAIL
if($m->Send()) {
header( "http://xyz.ie/thankyouurl.php" );
}
else
{
header( "http://xyz.ie/errorurl.php" );
}
为:
// @SEND MAIL
if($m->Send()) {
header("Location: http://xyz.ie/thankyouurl.php");
} else {
header("Location: http://xyz.ie/errorurl.php");
}
exit();
有关详细信息,请访问:http://php.net/manual/en/function.header.php
答案 1 :(得分:1)
你的标题错误。
header("Location: http://xyz.ie/thankyouurl.php");
exit();
答案 2 :(得分:0)
这是
header("Location: http://...");