簡體   English   中英

這種簡單的聯系方式無法正常運行

[英]This simple contact form won't function properly

我創建了一個簡單的提交表單,用戶在其中輸入他們的電子郵件地址並單擊提交,然后將他們的電子郵件地址通過電子郵件發送給我,以便在郵件列表中使用。

由於某種原因,它總是給我同樣的錯誤,並且實際上不會發送電子郵件:

抱歉,這似乎不是有效的電子郵件地址。

這是我的代碼:

<?php define('access', true); ?>
<?php
    // Configuration
    $emailTo = 'myemail@mydomain.com'; // The e-mail address
    $mySite = 'test Mailing List'; // The name of the website
    $subject = 'test | New Mailing Lister!';
    $msg = '';

    // If the form is submitted
    if(isset($_POST['submit'])) {
        // Check that the email entered is valid and not empty
        if(trim($_POST['email']) == '') {
            $hasError = true;
            $msg = '<p class="error">Sorry but that doesn\'t seem to be a valid e-mail address.</p>';
        } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
            $hasError = true;
            $msg = '<p class="error">Sorry but that doesn\'t seem to be a valid e-mail address.</p>';
        } else {
            $email = trim($_POST['email']);
        }

        // Are we error free? If so send away
        if(!isset($hasError)) {
            $body = "Someone has signed up for the test mailing list, the e-mail address they used is:\n\n<strong>$email</strong>";
            $headers = 'From: ' . $mySite . ' <' . $emailTo . '>' . "\r\n" . 'Reply-To: ' . $email;
            $msg = '<p class="thanks">Thanks for subscribing to test\'s services mailing list. We\'ll keep you posted on service updates!</p>';

            mail($emailTo, $subject, $body, $headers);
            $emailSent = true;
        }
    }
?>
<?php include('includes/html_header.php'); ?>
    <?php include('includes/header.php'); ?>

    <div id="container">
        <?php if(!isset($_GET['id'])) { ?>
        <div id="container_column-1">
            <h1>test</h1>
            <p>Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musica, sport etc, litot Europa usa li sam vocabular. Li lingues differe solmen in li grammatica, li pronunciation e li plu commun vocabules. Omnicos directe al desirabilite de un nov lingua franca: On refusa continuar payar custosi traductores. At solmen va esser necessi far uniform grammatica, pronunciation e plu sommun paroles. Ma quande lingues coalesce, li grammatica del resultant lingue es plu simplic e regulari quam ti del coalescent lingues. Li nov lingua franca va esser plu simplic e regulari quam li existent Europan lingues. It va esser tam simplic quam Occidental in fact, it va esser Occidental. A un Angleso it va semblar un simplificat Angles, quam un skeptic Cambridge amico dit me que Occidental es. Li Europan lingues es membres del sam familie.</p>
        </div>

        <div id="container_column-2">
            <h1>Coming <span>soon</span>!</h1>
            <p>We have an exciting new service to offer to our customers. We're not able to announce anything right now, but watch this space for updates in the very near future!</p>
            <p>Alternatively, you can enter your e-mail address below to be informed of any new services and offers we have. Don't worry, we won't sell on your e-mail address and you won't receive any junk mail!</p>

            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                <label>Be the first to hear about new services!</label>
                <input type="text" size="35" name="mailinglist" id="mailinglist" title="Enter your e-mail address" />
                <button type="submit" name="submit">&raquo;</button>
            </form>
            <?php if(isset($_POST['submit'])) { echo $msg; } ?>
        </div>
        <?php
            } else {
                include($_GET['id'] . ".php");
            }
        ?>
    </div>

    <?php include('includes/footer.php'); ?>
<?php include('includes/html_footer.php'); ?>

如果您要打開錯誤補給

<?php
error_reporting(E_ALL);
ini_set('display_errors','on');

那么您將收到錯誤消息:

Notice: Undefined index: email in %script% on line %line%

那就是因為您沒有在表單中提交任何電子郵件。 相反,您稱它為mailinglist

因此,請將字段名稱更改為email或將您的代碼更改為要求一個mailinglist字段。

很容易看到。 您的錯誤在這里:

<input type="text" size="35" name="mailinglist" id="mailinglist" title="Enter your e-mail address" />

應該是這樣的:

<input type="text" size="35" name="email" id="mailinglist" title="Enter your e-mail address" />

trim($_POST['email'])更改為trim($_POST['mailinglist'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM