【问题标题】:Add email validation to existing php file [duplicate]将电子邮件验证添加到现有的 php 文件 [重复]
【发布时间】:2015-02-13 19:10:26
【问题描述】:

如何为现有的 php 文件添加电子邮件验证?

PHP 文件:

    <?php
if (count($_POST)) {

    $email   = 'receivermail';
    $subject = 'our subject';
    $message = 'messageOK';
    $error   = 'messageNOTOK';
    $charset = 'utf-8';
    $head    = "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=$charset\r\n" . "Content-Transfer-Encoding: 8bit";
    $body    = '';
    foreach ($_POST as $name => $value) {
        if (is_array($value)) {
            for ($i = 0; $i < count($value); $i++) {
                $body .= "$name=" . (get_magic_quotes_gpc() ? stripslashes($value[$i]) : $value[$i]) . "\r\n";
            }
        } else
            $body .= "$name=" . (get_magic_quotes_gpc() ? stripslashes($value) : $value) . "\r\n";
    }
    echo mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head) ? $message : $error;
}
?>

另一个html文件中的表格:

<form method="post" action="name_of_the.php" name="ourform" >

【问题讨论】:

    标签: php validation email


    【解决方案1】:

    查看 filter_var 函数

    http://php.net/manual/en/function.filter-var.php

    filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)

    【讨论】:

    • 你真的应该扩展这个“答案”,因为它真的不比评论更好。
    猜你喜欢
    • 2011-06-21
    • 2011-04-06
    • 1970-01-01
    • 2011-01-22
    • 2011-01-09
    • 2011-03-30
    • 2011-07-16
    • 2019-11-02
    • 2013-09-19
    相关资源
    最近更新 更多