doukanwa6872 2015-05-12 19:26
浏览 12
已采纳

Php表单提交问题[关闭]

I've been trying to make a php form, so users can send email. But due to my lack of php knowledge at this point, this is a bit hard to solve. So i've gathered some finished snippets of code, but it still does not work.

Heres the php code that i have in a file named "submit.php"

<?php 
if(isset($_POST['submit'])){
    $to = "example@example.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "

" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "

" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

And heres the "form.php" that i have the html form in

<?php include('submit.php') ?>
    <div class="main-wrapper">
              <section class="contact-form">
        <form action="" method="POST">
         <h1>Contact</h1>
         <fieldset>

         <input maxlength="30" type="text" name="first_name" placeholder="John" required><br>

         <input maxlength="30" type="text" name="last_name" placeholder="Smith" required><br>

         <input maxlength="30" type="email" name="email" placeholder="john_doe@example.com" required>
          </fieldset>
         <fieldset>
         <textarea maxlength="300" placeholder="Write your text here...." id="message" name="message" cols="40" rows="6" required></textarea>
         <button name="submit" type="submit">Send Message</button>
          </fieldset>
        </form>
        </section>

And also someone told me that there is no security for the form, "because it does not strip html tag"

And how to i fix that?

  • 写回答

4条回答 默认 最新

  • duandu9260 2015-05-12 19:32
    关注

    Your server should have the Sendmail configured or a different mail server.

    To strip HTML you can use $message = strip_tags($message); $message2 = strip_tags($message2);

    Or you can use htmlspecialchars to convert special chars to HTML entities.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?