-1

我对 PHP 没有太多经验 - 我使用表单生成器来创建此表单。问题是表单发送了数百封空白电子邮件。任何人都可以帮我解决它吗?这是PHP代码:

 <?php

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

mail("blah@blah.com","MESSAGE: website","

Someone has submitted a message from your website!  Huzzah!

--------------------------------------------------------------------------------

CONTACT INFO:
" . $_POST['field_1'] . "
" . $_POST['field_2'] . " 

MESSAGE:
" . $_POST['field_3'] . " 

--------------------------------------------------------------------------------

Also you're a stud.

");

header("Refresh: 0;url=http://www.blah.com/thanks.html");

?>
4

1 回答 1

0

如果您只是确保有人实际POST通过(即实际使用表单)编辑数据,那么您会很高兴:

<?php
    $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

        if (!$_POST['field_1'] || !$_POST['field_2'] || !$_POST['field_3']) {
            header("Location: $where_form_is");
            exit;
        }

    mail("blah@blah.com","MESSAGE: website","Someone has submitted a message from your website!  Huzzah!
    CONTACT INFO:
    " . $_POST['field_1'] . "
    " . $_POST['field_2'] . " 

    MESSAGE:
    " . $_POST['field_3'] . " 
    Also you're a stud.");

    header("Refresh: 0;url=http://www.blah.com/thanks.html");
    exit;
?>
于 2012-09-30T05:02:19.360 回答