简体   繁体   English

PHP联系表单不适用于FF,但适用于Edge IE chrome和safari

[英]PHP contact form not working in FF but working in Edge IE chrome and safari

Dear folks the following code could be perfectly executed in IE (newest), Edge, Chrome and Safari but times out in FF, also it has issues with displaying the form in firefox. 亲爱的人们,以下代码可以在IE(最新),Edge,Chrome和Safari中完美执行,但在FF中超时,并且在firefox中显示表单也存在问题。

In Firefox once i press submit, it starts running the sendform.php it executes correctly, but it gets stuck once everything is filled out properly and it should send the form / email to me . 在Firefox中,一旦我按Submit,它就会开始运行sendform.php, 它会正确执行, 但是一旦一切正确填写它就会卡住,它应该向我发送表单/电子邮件

the page is also in use. 该页面也在使用中。 Tips and tricks for better / more secure code is appreciated. 感谢提供更好/更安全代码的技巧。

The contact from code ( as in kontakt.php): 来自代码的联系人(如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>

The submit code ( as in sendform.php): 提交代码(如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);
}

?>

I honestly do not know what causes, the issue, could be it is only my Firefox though i doubt it. 老实说,我不知道是什么原因引起的,可能是我怀疑它只是我的Firefox。 Cheers and Thanks in advance. 预先加油和谢谢。

My guess is there are errors and Firefox is not sending a referrer so the redirect never gets sent. 我的猜测是有错误,并且Firefox没有发送引荐来源网址,因此重定向从未发送。

Could you by any chance be sending any text that might accidentally become less than 3 characters when converted to UTF-8 or when otherwise processed? 您能否发送任何转换为​​UTF-8或进行其他处理时可能会意外少于3个字符的文本?

Being able to see the contents of $err would help narrow that down or exclude that possibility. 能够看到$err的内容将有助于缩小范围或排除这种可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM