Связывание контактной формы со страницей благодарности

Я пытаюсь связать контактную форму с 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

Решение

Используйте расположение заголовка, чтобы перенаправить на другую страницу:

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

Другие решения

Вы неправильно используете заголовок.

header("Location: http://xyz.ie/thankyouurl.php");
exit();
1

Это

header("Location: http://...");
0
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector