douqiaoru2583 2019-08-07 18:38
浏览 51

PHP:有没有理由不接收电子邮件? [重复]

This question already has an answer here:

I want to make a simple contact form but I guess I am out of luck again. I tested it on a website I hosted on 000webhost. I don't receive any e-mails. I am pretty much a newbie at PHP, so what is the reason? Is it my code? Or it's the hosting? Thanks!

<?php
        $recipient = "************@gmail.com";
        $first_name = $last_name = $email = $subject = $message = "";
        $first_name_empty = $last_name_empty = $email_invalid = $subject_empty = $message_empty = "";
        $trust = 0;

        function sending($input) {
            $input = trim($input);
            $input = stripslashes($input);
            $input = htmlspecialchars($input);
            return $input;
        }

        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (empty($_POST["first_name"]) || !preg_match("/^[a-zA-Z ]*$/", $first_name)) {
                $first_name_empty = "First name is not specified or invalid.";
            }
            else {
                $first_name = sending($_POST["first_name"]);
                $trust++;
            }
            if (empty($_POST["last_name"]) || !preg_match("/^[a-zA-Z ]*$/", $last_name)) {
                $last_name_empty = "Last name is not specified or invalid.";
            }
            else {
                $last_name = sending($_POST["last_name"]);
                $trust++;
            }
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $email_invalid = "E-Mail is empty or invalid.";
            }
            else {
                $email = sending($_POST["email"]);
                $trust++;
            }
            if (empty($_POST["subject"])) {
                $subject_empty = "Unspecified subject.";
            }
            else {
                $subject = sending($_POST["subject"]);
                $trust++;
            }
            if (empty($_POST["message"])) {
                $message_empty = "Your message is empty.";
            }
            else {
                $message = sending($_POST["message"]);
                $trust++;
            }
            if ($trust == 5) {
                mail($recipient, $subject, "From: " . $email . "
" . $message);
            }
            else {
                $trust = 0;
            }
        }
        ?>
        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
            <h1>Contact Me</h1>
            <input name="first_name" placeholder="First Name" type="name" />
            <input name="last_name" placeholder="Last Name" type="name" />
            <input name="email" placeholder="E-Mail" type="email" />
            <input name="subject" placeholder="Subject" type="text" />
            <textarea cols="50" name="message" rows="12"></textarea>
            <input id="send" name="send" type="submit" value="Send">  
        </form>

Also, kind of out of context, is my code vulnerable to SQL injection? How can I detect that?

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记