【问题标题】:redirecting to thank you page after sending a message via contact form - php通过联系表格发送消息后重定向到感谢页面 - php
【发布时间】:2015-02-11 14:03:01
【问题描述】:

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

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

没有

// @发送邮件 如果($m->发送()){ header ("位置:http://xyz.ie/thankyouurl.php"); } 别的 { header ("位置: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;
}?>    

【问题讨论】:

  • 您能否向我发送信息,带标题的行在退出时应如何显示;我对php不熟悉。谢谢。

标签: php


【解决方案1】:

您的问题可能是因为您缺少第一个“if”的关闭“}”。

if($_REQUEST['action'] = 'email_send') {

我认为应该是之前:

函数 ip() {

而且我认为你不需要退出线。

【讨论】:

  • 感谢您的回答,但不幸的是它没有帮助。您还有其他建议吗?
【解决方案2】:

原来下面的 ckmail 出了问题。所以我在strip_tags上改变了它。它成功了。

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

【讨论】:

    猜你喜欢
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 2015-03-10
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多