dongliaojing0554 2014-01-23 00:32
浏览 53
已采纳

php邮件表单不起作用[关闭]

I think I fixed this. This was the original:

<?php
    if(isset($_POST['email'])) {

    $email = $_POST['email'];
    $name = $_POST['name'];
    $message = $_POST['message'];;
    $subject = $email = $_POST['subject'];;

    $email_to = $email;
    $header = 'From: 1totheN <website@1tothen.com>' . "
";
    function clean_text($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }
    $email_message .= "Name: ".clean_text($email)."
";
    $email_message .= "Email: ".clean_text($email)."
";
    $email_message .= "Message: ".clean_text($message)."
";
    @mail($email_to, $subject, $email_message, $header);
    echo "Your message has been sent.";

}
?>

Here's the markup on the HTML page:

<form class="contact-form" id="subscribeForm" action="mail.php" method="post">
       <input type="text" name="name" class="required" placeholder="YOUR NAME">
       <input type="text" name="email" class="required email" placeholder="EMAIL ADDRESS">
       <input type="text" name="subject" class="required last" placeholder="SUBJECT">
       <textarea name="message" placeholder="YOUR MESSAGE"></textarea>
       <input type="submit" name="submit" value="SUBMIT YOUR MESSAGE">
       <h6 id="form_result">Your email will not be published.</h6>
</form>

This is the fix:

$email_to = "webmail@1tothen.com";
$header = 'From: 1totheN <webmail@1tothen.com>' . "
";
$email_message .= "Name: ".clean_text($name)."
";

I think that fixes it. I added an email to the $email_to field, and added the $name. Seems to work.

  • 写回答

1条回答 默认 最新

  • doushi6947 2014-01-23 00:47
    关注

    The below now works. It's just small syntactic mistakes, you had a few additional ; and this line is wrong and presumably a mistake: $subject = $email = $_POST['subject'];

    I also moved the function outside of the if statement...it's not incorrect to have it there, it just looks a bit weird.

    function clean_text($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
    }
    
    if(isset($_POST['email'])) {
        $email = $_POST['email'];
        $name = $_POST['name'];
        $message = $_POST['message'];
        $subject = $_POST['subject'];
    
        $email_to = $email;
        $header = 'From: 1totheN <website@1tothen.com>' . "
    ";
        $email_message .= "Name: ".clean_text($email)."
    ";
        $email_message .= "Email: ".clean_text($email)."
    ";
        $email_message .= "Message: ".clean_text($message)."
    ";
        @mail($email_to, $subject, $email_message, $header);
        echo "Your message has been sent.";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点