如何将用户的表单发送到我的电子邮件? HTML、CSS、JS?

问题描述 投票:0回答:1

HTML 格式:

<div class="contact-form">
            <form action="">
                <input type="name" placeholder="Your Name" required>
                <input type="email" placeholder="Your Email Address">
                <input type="" placeholder="Your Mobile Number" required>
                <textarea name="" id="" cols="35" rows="10" placeholder="How Can I Help You?" required></textarea>
                <input type="submit" value="Send Message" class="submit" required>
            </form>

        </div>

CSS 形式:

.contact-form form{
    position: relative;
}
.contact-form form input,
form textarea{
    width: 100%;
    padding: 14px;
    background: var(--bg-color);
    color: var(--text-color);
    border: none;
    outline: none;
    font-size: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
}
.contact-form textarea{
    resize: none;
    height: 240px;
}
.contact-form .submit{
    display: inline-block;
    font-size: 16px;
    background: var(--main-color);
    color: var(--text-color);
    width: 160px;
    transition: all .45s ease;
}
.contact-form .submit:hover{
    transform: scale(1.1);
    cursor: pointer;
}

如何将用户的表单发送到我的电子邮件? HTML、CSS、JS?

刚开始学js,有点不清楚这种情况下怎么实现。在这里,表格本身: enter image description here

javascript html css forms html-email
1个回答
0
投票

您需要服务器端脚本语言,如php、pythong、nodejs来处理表单数据并发送到您的电子邮件地址。

使用 php,你可以做一些像这样的基本操作作为参考,根据你自己的代码进行调整。

html 表格

<form action="form-handler.php" method="post">
  <input type="name" placeholder="Your Name" required>
  <input type="email" placeholder="Your Email Address">
  <input type="" placeholder="Your Mobile Number" required>
  <textarea name="" id="" cols="35" rows="10" placeholder="How Can I Help You?" required></textarea>
  <input type="submit" value="Send Message" class="submit" required>
</form>

表单处理程序.php

<?php
  $to = "[email protected]";
  $subject = "New Contact Form Submission";
  $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
  $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  $mobile = filter_var($_POST['mobile'], FILTER_SANITIZE_STRING);
  $message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
  $message = "Name: " . $name . "\n";
  $message .= "Email: " . $email . "\n";
  $message .= "Mobile: " . $mobile . "\n";
  $message .= "Message: " . $message . "\n";
  $headers = "From: [email protected]" . "\r\n" .
  "Reply-To: " . $email . "\r\n" .
  "X-Mailer: PHP/" . phpversion();
  mail($to, $subject, $message, $headers);
?>

再次注意这只是一个示例,您也可以使用 python 或 nodejs。

© www.soinside.com 2019 - 2024. All rights reserved.