【问题标题】:"Send" Button linked to contact form“发送”按钮链接到联系表
【发布时间】:2019-01-25 03:31:39
【问题描述】:

我的网页中有一个联系表格,其中包含 3 个区域的名称、电子邮件和文本(无主题),以及表格下方的发送按钮。我应该怎么做才能使按钮工作?我希望用户写下他们的姓名(最终将成为电子邮件的主题)、他们的电子邮件和他们想要发送的文本,并且我想从他们那里收到以他们的名字作为主题的电子邮件,他们的电子邮件和他们将作为电子邮件正文编写的文本。另外,我不希望按钮打开用户电子邮件,如 Outlook 等。我希望它默默地发生。所以结果将是用户在联系表格中写下文本,按发送,然后我收到电子邮件。

非常感谢,提前!!!

拉斐尔。

【问题讨论】:

    标签: html css email sendmail contact-form


    【解决方案1】:

    首先你必须学习 php 才能使它工作。您不能仅使用表单设计发送邮件。 此外,您必须在服务器上上传文件。发送邮件需要 SMTP,这在 localhost 上不起作用。

    HTML:

    <form action="mail_handler.php" method="
    FullName: <input type="text" name="full_name"><br>
    Email: <input type="text" name="email"><br>
    Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
    <input type="submit" name="submit" value="Submit">
    </form>
    

    mail_handler.php

     <?php 
        if(isset($_POST['submit'])){
            $to = "email@example.com"; // this is your Email address
            $from = $_POST['email']; // this is the sender's Email address
            $full_name = $_POST['full_name'];
            $subject = "Form submission";
            $subject2 = "Copy of your form submission";
            $message = $full_name . " wrote the following:" . "\n\n" . $_POST['message'];
            $message2 = "Here is a copy of your message " . $full_name . "\n\n" . $_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 " . $full_name . ", we will contact you";
            }
        ?>
    

    我建议您在实施之前先看一些教程。实现前需要先了解php。

    【讨论】:

    • 感谢@Upendra Joshi 的提示。我将立即开始研究 PHP!
    猜你喜欢
    • 2017-09-05
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 2021-04-05
    • 2015-07-07
    • 1970-01-01
    相关资源
    最近更新 更多