-2

嗨,我在 PHP 网站上的转发有问题。

当您提交我的联系表格时,它应该加载一个新页面thank-you.html,但这不起作用。有替代方案吗?

这里的代码:

<?php 
$your_email ='test@gmail.com';// <<=== update to your email address

session_start();
    $errors = '';
    $firma= '';
    $vorname= '';
    $nachname = '';
    $strassenr = '';
    $plzort = '';
    $telefon = '';
    $emailen = '';
    $telefonisch = '';
    $preislisteunterlagen = '';
    $displaymiete = '';
    $displayverkauf = '';
    $led_lampen = '';
    $visitor_email = '';
    $user_message = '';

if(isset($_POST['submit']))
{
    $firma = $_POST['firma'];
    $vorname = $_POST['vorname'];
    $nachname = $_POST['nachname'];
    $strassenr = $_POST['strassenr'];
    $plzort = $_POST['plzort'];
    $telefon = $_POST['telefon'];
    $telefonisch = $_POST['telefonisch'];
    $emailen = $_POST['emailen'];
    $displaymiete = $_POST['displaymiete'];
    $displayverkauf = $_POST['displayverkauf'];
    $led_lampen = $_POST['led_lampen'];
    $preislisteunterlagen = $_POST['preislisteunterlagen'];
    $visitor_email = $_POST['email'];
    $user_message = $_POST['message'];
    ///------------Do Validations-------------
    if(empty($nachname)||empty($visitor_email))
    {
        $errors .= "\n $nachname und Email sind erforderliche Felder. ";    
    }
    if(IsInjected($visitor_email))
    {
        $errors .= "\n Geben Sie eine g&uuml;ltige Email-Adresse an!";
    }
    if(empty($_SESSION['6_letters_code'] ) ||
      strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
    {
    //Note: the captcha code is compared case insensitively.
    //if you want case sensitive match, update the check above to
    // strcmp()
        $errors .= "\n Der Captcha Code stimmt nicht &uuml;berein!";
    }

    if(empty($errors))
    {
        //send the email
        $to = $your_email;
        $subject="Formular Swissdisplays.ch";
        $from = $your_email;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

        $body = "$nachname hat das Kontaktformular von Swissdisplay.ch ausgefüllt\n".
        "Firma: $firma\n".
        "Vorname: $vorname\n".
        "Nachname: $nachname\n".
        "Strasse / Nr: $strassenr\n".
        "PLZ / Ort: $plzort\n".
        "Telefon: $telefon\n".
        "kontaktaufnahme: $telefonisch\n".
        "kontaktaufnahme: $emailen\n".
        "kontaktaufnahme: $preislisteunterlagen\n".
        "Information: $displaymiete\n".
        "Information: $displayverkauf\n".
        "Information: $led_lampen\n".
        "Email: $visitor_email \n".
        "Message: \n ".
        "$user_message\n".
        "IP: $ip\n";    

        $headers = "From: $from \r\n";
        $headers .= "Reply-To: $visitor_email \r\n";

        mail($to, $subject, $body,$headers);

        header('Location: thank-you.html');
    }
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>

<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>    
</head>

<body>

    <div id='contact_form_wrapper'>
    <div id='contact_icon'></div>

<?php
    if(!empty($errors)){
    echo "<p class='err'>".nl2br($errors)."</p>";
    }
?>
      <div id='contact_form_errorloc' class='err'></div>
        <form method="POST" name="contact_form" 
        action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
        <p>
<br>

        <label for='firma'>Firma:</label><br>
        <input type="text" name="firma" class="eingabe" value='<?php echo htmlentities($firma) ?>' >
        </p>

        <p>
        <label for='vorname'>Vorname:</label><br>
        <input type="text" name="vorname" class="eingabe" value='<?php echo htmlentities($vorname) ?>' >

        </p>
        <p>
        <label for='nachname'>Nachname:</label><br>
        <input type="text" name="nachname" class="eingabe" value='<?php echo htmlentities($nachname) ?>' >

        </p>
        <p>
        <label for='strassenr'>Strasse / Nr.:</label><br>
        <input type="text" name="strassenr" class="eingabe" value='<?php echo htmlentities($strassenr) ?>' >
        </p>


        <p>
        <label for='plzort'>PLZ / Ort:</label><br>
        <input type="text" name="plzort"  class="eingabe"value='<?php echo htmlentities($plzort) ?>' >
        </p>
        <p>
        <label for='telefon'>Telefon:</label><br>
        <input type="text" name="telefon"  class="eingabe" value='<?php echo htmlentities($telefon) ?>' >
        </p>


        <p>
        <label for='kontaktaufnahme'>Kontaktaufnahme:</label><br>

        <input type="checkbox" name="telefonisch" value="telefonisch" <?php if (isset($_POST["telefonisch"])) echo 'checked="checked"'; ?> > Telefon<br>

        <input type="checkbox" name="emailen" value="email" <?php if (isset($_POST["emailen"])) echo 'checked="checked"'; ?> > E-Mail<br>

        <input type="checkbox" name="preislisteunterlagen" value="preisliste und unterlagen" <?php if (isset($_POST["preislisteunterlagen"])) echo 'checked="checked"'; ?> > Preisliste / Unterlagen f&uuml;r LED-Werbung<br>
        </p>

        <p>
        <label for='information'>Information:</label><br>
        <input type="checkbox" name="displaymiete" value="displaymiete" <?php if (isset($_POST["displaymiete"])) echo 'checked="checked"'; ?> > Displaymiete<br>
        <input type="checkbox" name="displayverkauf" value="displayverkauf" <?php if (isset($_POST["displayverkauf"])) echo 'checked="checked"'; ?> > Displayverkauf<br>
        <input type="checkbox" name="led_lampen" value="led_lampen" <?php if (isset($_POST["led_lampen"])) echo 'checked="checked"'; ?> > LED-Lampen<br>
        </p>


        <p>
        <label for='email'>Email: </label><br>
        <input type="text" name="email" class="eingabe" value='<?php echo htmlentities($visitor_email) ?>'>
        </p>

        <p>
        <label for='message'>Mitteilung:</label> <br>
        <textarea name="message"  class="eingabe" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
        </p><br><br><br><br>


        <p>
        <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg'><br>
        <label for='message'>Code hier einf&uuml;gen :</label><br>
        <input id="6_letters_code" name="6_letters_code" cols=10 type="text"><br>
        <small>Klicken Sie<a href='javascript: refreshCaptcha();'>hier</a> um einen neuen Code zu erhalten</small>
        </p>
        <input type="submit" value="Abschicken" name='submit'>
        </form>



<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("firma","req","Bitte Firma eingeben"); 
frmvalidator.addValidation("vorname","req","Bitte Vorname eingeben"); 
frmvalidator.addValidation("nachname","req","Bitte Nachname eingeben"); 
frmvalidator.addValidation("strassenr","req","Bitte Strasse eingeben"); 
frmvalidator.addValidation("plzort","req","Bitte PLZ/Ort eingeben"); 
frmvalidator.addValidation("telefon","req","Bitte Telefon eingeben"); 
frmvalidator.addValidation("email","req","Bitte Email eingeben"); 
frmvalidator.addValidation("email","email","Bitte eine g&uuml;ltige Emailadresse eingeben"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()

{
    var img = document.images['captchaimg'];
    img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>


</div><!-------End contact_form_wrapper-------->

</body>
</html>
4

2 回答 2

0

很可能在您的标题之前有输出(“Location ...”);更有可能电子邮件功能失败,您需要检查错误并进行一些调试以查看错误发生在哪里,以及您在哪里得到意外输出。

于 2013-09-10T10:49:58.433 回答
0

首先,确认您的验证码帖子是否有效。第二次检查thank-you.html 文件是否存在。截至目前,提交邮件功能并检查发生了什么。

于 2013-09-10T11:01:40.900 回答