表格mailto主题,主题名称=“ XXXX” +输入

时间:2019-02-19 07:32:26

标签: html

如何通过表单输入将邮件主题设置为“某些文本” +名称

<a href="mailto:someone@yoursite.com?subject=Testing+(Name)">Email Us</a> 

这是我的代码

<form action="/action_page.php" target="_blank">
        <input type="text" placeholder="Name" required name="Name">
        <input type="text" placeholder="Email" required name="Email">
        <input type="text" placeholder="Contact" required name="Contact">
        <input type="text" placeholder="Message" required name="Message">
    <button type="submit">
      <a href="mailto:someone@yoursite.com?subject=Testing+(Name)">Email Us</a> 
    </button>
  </form>

例如 用户输入名称为“ Cyrus”,那么我的mailto主题应为Testing(Cyrus)。

1 个答案:

答案 0 :(得分:1)

您可以使用我命名为demo-contacts.php的此php页面

<?php
if( isset($_POST['name']) )
{
    $to = 'youremail@yoursite.com'; // Replace with your email

    $subject = $_POST['subject'];
    $message = $_POST['message'] . "\n\n" . 'Regards, ' . $_POST['name'] . ' - ' . $_POST['email'] . '.';
    $headers = 'From: ' . $_POST['name'] . "\r\n" . 'Reply-To: ' . $_POST['email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

    if( $_POST['copy'] == 'on' )
    {
        mail($_POST['email'], $subject, $message, $headers);
    }
}
?>

和此表单分别在名为contact.php的页面上

<form action="demo-contacts.php" method="post" id="sky-form" class="sky-form">
          <header>Contact <strong>Form</strong></header>
          <fieldset>
            <div class="row">
              <section class="col col-6">
                <label class="label">Name</label>
                <label class="input"> <i class="icon-append icon-user"></i>
                  <input type="text" name="name" id="name">
                </label>
              </section>
              <section class="col col-6">
                <label class="label">E-mail</label>
                <label class="input"> <i class="icon-append icon-envelope-alt"></i>
                  <input type="email" name="email" id="email">
                </label>
              </section>
            </div>
            <section>
              <label class="label">Subject</label>
              <label class="input"> <i class="icon-append icon-tag"></i>
                <input type="text" name="subject" id="subject">
              </label>
            </section>
            <section>
              <label class="label">Message</label>
              <label class="textarea"> <i class="icon-append icon-comment"></i>
                <textarea rows="4" name="message" id="message"></textarea>
              </label>
            </section>
            <section>
              <label class="checkbox">
                <input type="checkbox" name="copy" id="copy">
                <i></i>Send a copy to my e-mail address</label>
            </section>
          </fieldset>
          <footer>
            <button type="submit" class="button">Send message</button>
          </footer>
          <div class="message"> <i class="icon-ok"></i>
            <p>Your message was successfully sent!</p>
          </div>
        </form>

我还使用了此样式表,您可以通过此链接http://www.dewetcomputers.com/js/form/sky-forms.css

从我的网站上免费下载该样式表。

这个缩小的Jquery,您可以下载http://www.dewetcomputers.com/js/form/jquery.form.min.js

如果您想查看表单的外观,也可以在这里http://www.dewetcomputers.com/contact.php

<link rel="stylesheet" href="js/form/sky-forms.css" type="text/css" media="all">

随时问其他问题,或者是否遇到其他问题