简体   繁体   English

这种简单的联系方式无法正常运行

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

I've created a simple submit form, where the user inputs their e-mail address and clicks submit and their e-mail address is e-mailed to me for use in a mailing list. 我创建了一个简单的提交表单,用户在其中输入他们的电子邮件地址并单击提交,然后将他们的电子邮件地址通过电子邮件发送给我,以便在邮件列表中使用。

For some reason it keeps giving me the same error and won't actually send the e-mail: 由于某种原因,它总是给我同样的错误,并且实际上不会发送电子邮件:

Sorry but that doesn't seem to be a valid e-mail address. 抱歉,这似乎不是有效的电子邮件地址。

Here's my code: 这是我的代码:

<?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'); ?>

if you would turn on error repoting 如果您要打开错误补给

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

then you would end up with the error message: 那么您将收到错误消息:

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

and thats because you don't have any email filed in your form. 那就是因为您没有在表单中提交任何电子邮件。 instead you called it mailinglist 相反,您称它为mailinglist

so change the field name to email or change your code to ask for a mailinglist field. 因此,请将字段名称更改为email或将您的代码更改为要求一个mailinglist字段。

It's pretty easy to see. 很容易看到。 Your error is here: 您的错误在这里:

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

it should be this: 应该是这样的:

<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