Эта простая контактная форма не будет работать должным образом - PullRequest
0 голосов
/ 01 октября 2010

Я создал простую форму отправки, где пользователь вводит свой адрес электронной почты и нажимает кнопку отправки, а его адрес электронной почты отправляется мне по электронной почте для использования в списке рассылки.

По какой-то причине он продолжает выдавать мне ту же ошибку и фактически не отправляет электронное письмо:

Извините, но это неправильный адрес электронной почты.

Вот мой код:

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

Ответы [ 3 ]

2 голосов
/ 01 октября 2010

, если вы включите сообщение об ошибке

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

, то вы получите сообщение об ошибке:

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

, и это потому, что у вас нет электронной почты, поданной вваша форма.вместо этого вы назвали его mailinglist

, поэтому измените имя поля на электронную почту или измените свой код, чтобы запросить поле mailinglist.

1 голос
/ 01 октября 2010

изменить trim($_POST['email']) на trim($_POST['mailinglist']).

1 голос
/ 01 октября 2010

Это довольно легко увидеть.Ваша ошибка здесь:

<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" />
...