dongyo7931 2016-03-23 21:37
浏览 112

PHP联系表单在FF中不起作用,但在Edge IE chrome和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.

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.

the page is also in use. Tips and tricks for better / more secure code is appreciated.

The contact from code ( as in 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):

    <?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. Cheers and Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongshanxun6479 2016-03-23 22:28
    关注

    My guess is there are errors and Firefox is not sending a referrer so the redirect never gets sent.

    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?

    Being able to see the contents of $err would help narrow that down or exclude that possibility.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号