PHP联系表单在FF中不起作用,但在Edge IE chrome和safari

时间:2016-03-23 21:37:25

标签: php html firefox twitter-bootstrap-3

亲爱的朋友们,下面的代码可以在IE(最新版),Edge,Chrome和Safari中完美地执行,但是在FF中出现问题,还有在firefox中显示表单的问题。

在Firefox中,当我按下提交时,它会开始运行它正确执行的sendform.php,但是一旦所有内容都正确填写它就会卡住,它应该将表单/电子邮件发送给我。< / p>

页面也在使用中。感谢提供更好/更安全代码的提示和技巧。

来自代码的联系人(如kontakt.php):

<?php
session_start();

$success='';
if($_SESSION['sent'] == '1')
{
    $success='<div class="container">
                <h3>Vielen Dank. Ihre Nachricht wurde übermittelt.</h3>
            </div>';

    $css='<style type="text/css">#phpcontactform{display:none;}</style>';

    unset($_SESSION['sent']);
}

?>

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

    <meta name="keywords" content="mieten,Bruchsal,Vermietung,Büro,Hallen,Standort,Industrie,Gewerbe,Gewerbepark,Produktion,Karlsruhe">
    <meta name="description" content="Vermietung von Büro, Hallen, Lager- und Produktionsflächen im Gewerbepark Bruchsal. Lageplan und Hallenplan.">
    <meta name="robots" content="INDEX,FOLLOW">
    <meta name="page-topic" content="Kontaktformular">

    <title>GWB Kontakt</title>

    <link href="files/bootstrap.min.css" rel="stylesheet">
    <link href="files/main.css" rel="stylesheet">

    <?=$css?>

    <script type="text/javascript" src="files/jquery-1.11.3.min.js"></script>

    <script type="text/javascript" src="files/bootstrap.min.js"></script>

    <script type="text/javascript" src="files/myaffix.js"></script>

    <script> 

        $(document).ready(function () {

        //code for dynamic navbar banner
            myaffix();

            $(window).on("resize", function () {
                myaffix();   
            }); 

        });
    </script>

</head>

<body>

    <div class="logo">
        <img class="featurette-image img-responsive center-block" src="images/banner.jpg" alt="Generic Banner">
    </div>

    <div id="placeme">
    </div>

    <div id="nav-wrapper">
        <div id="nav" class="navbar navbar-inverse">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="index.html">Gewerbepark Bruchsal</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="standort.html">Standort</a></li>
                        <li><a href="bilder.html">Bilder</a></li>
                        <li><a href="hallenplan.html">Hallenplan</a></li>
                        <li><a href="ausstattung.html">Ausstattung</a></li>
                        <li class="active"><a href="kontakt.php">Kontakt</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="container">

        <h1>Kontakt</h1>

        <hr>

        <p>ARES GmbH, Richard-Wagner-Straße 23, 50674 Köln
            <br>Telefon: 0221-2717290, Fax: 0221-2717291, Email: <a href="mailto:info@gewerbepark-bruchsal.de">info@gewerbepark-bruchsal.de</a>
        </p>

        <hr size="5px">

        <div class="container">

        <h2>Schreiben Sie uns direkt an</h2>

        <form id="phpcontactform" class="form-horizontal" role="form" method="post" action="files/sendform.php">

            <div class="form-group <?php if (isset($_SESSION['err']['name'])) {if ($_SESSION['err']['name'] == 'okay') {echo 'has-success has-feedback';} else {echo 'has-error has-feedback';}}  ?> ">
                <label class="control-label col-sm-2" for="name">Name:</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control <?php if (isset($_SESSION['err']['name'])) {if ($_SESSION['err']['name'] == 'okay') {echo 'alert alert-success';} else {echo 'alert alert-danger';}}  ?>" name="name" id="name" placeholder="Ihr Name" maxlength="100" value="<?php echo ($_SESSION['post']['name']); ?>">
                    <?php if (isset($_SESSION['err']['name'])) {if ($_SESSION['err']['name'] == 'okay') {echo "<span class='glyphicon glyphicon-ok form-control-feedback'></span>";} 
                    else {echo "<span class='glyphicon glyphicon-remove form-control-feedback'></span><p class='text-danger'>{$_SESSION['err']['name']}</p>";} }?>
                </div>
            </div>

            <div class="form-group <?php if (isset($_SESSION['err']['email'])) {if ($_SESSION['err']['email'] == 'okay') {echo 'has-success has-feedback';} else {echo 'has-error has-feedback';}}  ?>">
                <label class="control-label col-sm-2" for="email">Email:</label>
                <div class="col-sm-10">
                    <input type="email" class="form-control <?php if (isset($_SESSION['err']['email'])) {if ($_SESSION['err']['email'] == 'okay') {echo 'alert alert-success';} else {echo 'alert alert-danger';}}  ?>" name="email" id="email" placeholder="Ihre Emailadresse" value="<?php echo ($_SESSION['post']['email']); ?>">    
                    <?php if (isset($_SESSION['err']['email'])) {if ($_SESSION['err']['email'] == 'okay') {echo "<span class='glyphicon glyphicon-ok form-control-feedback'></span>";} 
                    else {echo "<span class='glyphicon glyphicon-remove form-control-feedback'></span><p class='text-danger'>{$_SESSION['err']['email']}</p>";} }?>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-2" for="telefon">Telefon:</label>
                <div class="col-sm-10">          
                    <input type="tel" class="form-control" name="telefon" id="telefon" placeholder="Ihre Telefonnummer - für schnellere Rücksprache" maxlength="50" value="<?php echo ($_SESSION['post']['telefon']); ?>">
                </div>
            </div>

            <div class="form-group <?php if (isset($_SESSION['err']['message'])) {if ($_SESSION['err']['message'] == 'okay') {echo 'has-success has-feedback';} else {echo 'has-error has-feedback';}}  ?>">
                <label class="control-label col-sm-2" for="message">Nachricht:</label>
                <div class="col-sm-10">
                    <textarea class="form-control <?php if (isset($_SESSION['err']['message'])) {if ($_SESSION['err']['message'] == 'okay') {echo 'alert alert-success';} else {echo 'alert alert-danger';}}  ?>" name="message" id="message" placeholder="Ihr Anliegen" maxlength="1000"><?php echo ($_SESSION['post']['message']); ?></textarea>
                    <?php if (isset($_SESSION['err']['message'])) {if ($_SESSION['err']['message'] == 'okay') {echo "<span class='glyphicon glyphicon-ok form-control-feedback'></span>";} 
                    else {echo "<span class='glyphicon glyphicon-remove form-control-feedback'></span><p class='text-danger'>{$_SESSION['err']['message']}</p>";} }?>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" name="senden" id="btn-senden" class="btn btn-lg btn-warning">Senden</button>
                </div>
            </div>

        </form>

        <?=$success?>

        </div>

    </div>

    <div class="container">
        <hr>
        <footer>
            <p>&copy; 2015 ARES GmbH <a href="impressum.html">Impressum</a></p>
        </footer>
    </div>

</body>
</html>

提交代码(如sendform.php中所示):

    <?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
// date_default_timezone_set('Etc/UTC');
//Create a new PHPMailer instance
require "phpmailer/PHPMailerAutoload.php";

session_start();

foreach($_POST as $k=>$v)
{
    if(ini_get('magic_quotes_gpc'))
    $_POST[$k]=stripslashes($_POST[$k]);

    $_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}


// Fehlerkontrolle

// kreiere Fehlerarray

$err = array();


// Füge entsprechende Fehler hinzu
if(!checkLen('name'))
    $err['name']='Sie haben keinen Namen angegeben.';
else
    $err['name']='okay';

if(!checkLen('email'))
    $err['email']='Sie haben keine Email angegeben.';
elseif(!checkEmail($_POST['email']))
    $err['email']='Die Email scheint nicht gültig zu sein.';
else
    $err['email']='okay';

if(!checkLen('message'))
    $err['message']='Sie haben keine Nachricht hinterlassen.';
else
    $err['message']='okay';

// Speichere variablen in Seitenübergreifender Variable (SESSION)

$_SESSION['post']=$_POST;

$_SESSION['err']=$err;

//check if there are no errors

if(count(array_unique($err)) === 1)
{

    //create message body
    $msg=
    'Name:  '.$_POST['name'].'<br />
    Email:  '.$_POST['email'].'<br />
    IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />

    Message:<br /><br />

    '.nl2br($_POST['message']).'
    ';

    //Create a new PHPMailer instance
    $mail = new PHPMailer;

    //Tell PHPMailer to use SMTP
    $mail->isSMTP();

    //Set the hostname of the mail server
    $mail->Host = 'smtp.XXXXX.XXX';
    // use
    // $mail->Host = gethostbyname('smtp.gmail.com');
    // if your network does not support SMTP over IPv6

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;

    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';

    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;

    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "XXXX@XXXXX.XXX";

    //Password to use for SMTP authentication
    $mail->Password = "XXXXXXXXX";

    //Set who the message is to be sent from
    $mail->setFrom($_POST['email'], $_POST['name']);

    //Set an alternative reply-to address
    $mail->addReplyTo('replyto@example.com', 'First Last');

    //Set who the message is to be sent to
    $mail->addAddress('XXXX@XXXX.XXX', 'Kontakt Formular');

    //Set the subject line
    $mail->Subject = "Eine Anfrage von ".$_POST['name'].".";

    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML($msg);


    //send the message
    $mail->send();

    //send silent notice that mail was sent
    $_SESSION['sent']= '1';



    if($_SERVER['HTTP_REFERER'])
        header('Location: '.$_SERVER['HTTP_REFERER']);

    unset($_SESSION['post']);
    unset($_SESSION['err']);

    exit;

}


// if there are errors by user filling the form
else
{

    if($_SERVER['HTTP_REFERER'])
        header('Location: '.$_SERVER['HTTP_REFERER']);

    exit;

}


function checkLen($str,$len=2)
{
    return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}

function checkEmail($str)
{
    return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}

?>

老实说,我不知道是什么原因,问题,可能只是我的Firefox,虽然我对此表示怀疑。欢呼并提前致谢。

1 个答案:

答案 0 :(得分:0)

我的猜测是有错误,Firefox没有发送引荐来源,因此重定向永远不会被发送。

转换为UTF-8或处理时,您是否可以发送任何可能意外变为少于3个字符的文本?

能够查看$err的内容有助于缩小范围或排除这种可能性。