将联系表格与感谢页面链接


Linking contact form with thank-you page

>我正在尝试将联系表单与感谢网址链接.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;
}?>

使用标题位置重定向到其他页面:

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

你的使用标题错误。

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

It's

header("Location: http://...");