通过联系表单发送消息后重定向到感谢页面 - php

时间:2014-12-12 19:30:41

标签: php

我遇到问题,联系表格工作正常并显示消息"发送确定"发送后。但是,当我更改代码时,它将显示"感谢页面"在发送消息而不是简单的"发送确定"页面变为空白,邮件永远不会到达我的电子邮箱。为什么会这样?唯一改变的代码是:

        // @SEND MAIL
    if($m->Send()) {
        die('_sent_ok_'); 
    } else {
        die($m->ErrorInfo); 
    }    

NA

// @SEND MAIL     if($ m-> Send()){         标题("位置:http://xyz.ie/thankyouurl.php");     } else {         标题("位置:http://xyz.ie/errorurl.php");     }     出口();

这是当前版本的代码。

<?php
@ini_set('display_errors', 1);
@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 ("Location: http://xyz.ie/thankyouurl.php");
    } else {
        header ("Location: http://xyz.ie/errorurl.php");
    }
    exit();

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;
}?>    

2 个答案:

答案 0 :(得分:0)

您的问题可能是因为您错过了第一个“if”的关闭“}”。

  

if($ _ REQUEST ['action'] ='email_send'){

我认为应该在之前:

  

function ip(){

我认为你不需要退出线。

答案 1 :(得分:0)

原来,下面的ckmail正在考虑问题。所以我在strip_tags上改了它。它成功了。

  $array['email']     = isset($_REQUEST['email'])     ? ckmail($_REQUEST['email'])                                    : '';