添加当前代码

时间:2016-03-10 20:22:08

标签: php wordpress cookies

昨天有一位开发人员帮我解决了cookie问题,但在添加该代码后,我的表单没有向管理员发送任何邮件并填写表格。我昨天面临的问题是我无法立即访问cookie。

上一个代码:

<?php if(isset($_COOKIE['username']) || isset($_POST['username'])){ ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $('a.down').show().css("display", "block");
        });
    </script>
<?php } else {  include('login.php'); } ?>

我当前的代码:

<?php 
if(!isset($_COOKIE['username'])){
    setcookie("username", $_POST['username'], time() + (86400 * 30), "/");
    $username=$_POST['username'];
}
?>

<?php if (isset($_COOKIE['username']) || isset($username)){ ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $('a.down').show().css("display", "block");
        });
    </script>
<?php } else { include('login.php'); ?>

感谢您的时间。

我的cookie代码现在正在运行,我可以一次提交表单,但问题是我没有收到邮件。

这里是我的login.php文件代码:

<?php if(!isset($_COOKIE['username'])){
        setcookie("username", $_POST['username'], time() + (86400 * 30), "/");
       $username=$_POST['username'];
       }
?>

<?php if (isset($_COOKIE['username']) || isset($username)){ ?>

    <script type="text/javascript">
        jQuery(document).ready(function($){
            $('a.down-resources').show().css("display", "block");
        });
    </script>

<?php } else { 

    if(isset($_POST['submit'])){  

    if(!empty($_POST['username']) && !empty($_POST['email']) && !empty($_POST['phone'])) {

    $username = $_POST['username'];  
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $company = $_POST['company'];

    if ($username == $_POST['username'] && $email == $_POST['email']){
        if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
                echo "$email is not a valid email address";
            }

        $udomain = end(explode('@', $email));

        $domains = array("aol.com", "att.net", "comcast.net",
            "facebook.com", "gmail.com", "gmx.com", "googlemail.com", "google.com",
            "hotmail.com", "hotmail.co.uk", "mac.com", "me.com", "mail.com", "msn.com",
            "live.com", "sbcglobal.net", "verizon.net", "yahoo.com", "yahoo.co.uk",
            "email.com", "games.com", "gmx.net", "hush.com", "hushmail.com", "inbox.com",
            "lavabit.com", "love.com", "pobox.com", "rocketmail.com", "safe-mail.net",
            "wow.com", "ygm.com", "ymail.com", "zoho.com", "fastmail.fm", "bellsouth.net",
            "charter.net", "cox.net", "earthlink.net", "juno.com",
            "btinternet.com", "virginmedia.com", "blueyonder.co.uk", "freeserve.co.uk",
            "live.co.uk", "ntlworld.com", "o2.co.uk", "orange.net", "sky.com",
            "talktalk.co.uk", "tiscali.co.uk", "virgin.net", "wanadoo.co.uk", "bt.com",
            "sina.com", "qq.com", "naver.com", "hanmail.net", "daum.net", "nate.com",
            "yahoo.co.jp", "yahoo.co.kr", "yahoo.co.id", "yahoo.co.in", "yahoo.com.sg",
            "yahoo.com.ph", "hotmail.fr", "live.fr", "laposte.net", "yahoo.fr",
            "wanadoo.fr", "orange.fr", "gmx.fr", "sfr.fr", "neuf.fr", "free.fr",
            "gmx.de", "hotmail.de", "live.de", "online.de", "t-online.de", "web.de",
            "yahoo.de", "mail.ru", "rambler.ru", "yandex.ru", "hotmail.be", "live.be",
            "skynet.be", "voo.be", "tvcablenet.be", "hotmail.com.ar", "live.com.ar",
            "yahoo.com.ar", "fibertel.com.ar", "speedy.com.ar", "arnet.com.ar",
            "hotmail.com", "gmail.com", "yahoo.com.mx", "live.com.mx", "yahoo.com",
            "hotmail.es", "live.com", "hotmail.com.mx", "prodigy.net.mx", "msn.com");


        if (in_array($udomain, $domains)) {
            echo "Only use corporate email address";
        } else {
            define('WP_USE_THEMES', true);
            setcookie("username", $username, time() + (86400 * 30), "/");          
            /* send to 1st recipient */
            $to_1 = "example@yahoo.com";
            $from = "$email";
            $subject_1 = "Test";
            $message_1 = "Hello World!";

            $headers_1 = 'From: ' . $from . "\r\n";
            $headers_1 .= "MIME-Version: 1.0" . "\r\n";
            $headers_1 .= "Content-type:text/html;charset=utf-8" . "\r\n";

            mail($to_1, $subject_1, $message_1, $headers_1);

            /* send to 2nd recipient */
            $to_2 = "$email";
            $from_2 = "example@test.com";
            $subject_2 = "Thank you";
            $message_2 ="2nd Message to visitor";

            $headers_2 = 'From: ' . $from_2 . "\r\n";
            $headers_2 .= "MIME-Version: 1.0" . "\r\n";
            $headers_2 .= "Content-type:text/html;charset=utf-8" . "\r\n";

            mail($to_2, $subject_2, $message_2, $headers_2);
            header("Location: ".$_SERVER['HTTP_REFERER']);
        }  

        } else { echo 'Some Error Occured'; }  
    }  else { echo '<strong>Please enter the require fields.</strong> <br /> <br />'; }
}
?>

<p>To access complete information, please fill-in the form below and click on submit button. <br /></p>

<form action="" method="POST">
        Name * :<input name="username" type="text" value="<?php if(isset($_POST['submit'])){ echo $username;}?>">
        Email * :<input name="email" type="email" value="<?php if(isset($_POST['submit'])){ echo $email;}?>">
        <input name="submit" type="submit" value="Submit"><br />
        Company :<input name="company" type="text" value="<?php if(isset($_POST['submit'])){ echo $company;}?>">
        Phone * :<input name="phone" type="text" value="<?php if(isset($_POST['submit'])){ echo $phone;}?>">
    </div>
</form>
<?php } ?>

0 个答案:

没有答案