HTML / PHP表格在提交时给我发电子邮件

时间:2016-08-02 17:18:34

标签: php html forms

我正在尝试让我的HTML表单向我发送一封电子邮件,其中包含用户在表单中输入的数据。我的HTML:

 <form method="post" action="php/contact.php" id="contact_form">
          <div class="row">
              <div class="large-6 columns">
                <label for="contact_name">Your Name<em>*</em></label>
                <input type="text" placeholder="e.g. John Doe" id="contact_name" name="contact_name" class="required form-control">
              </div>
              <div class="large-6 columns contactEmail">
                <label for="contact_email">Your Email<em>*</em></label>
                <input type="email" placeholder="e.g. John@Doe.com" id="contact_email" name="contact_email" class="required email form-control">
              </div>
          </div>
          <div class="row">
          </div>
          <div class="row">
            <div class="large-12 columns">
              <label for="contact_message">Your Message<em>*</em></label>
              <textarea placeholder="e.g. Let's work together!" id="contact_message" name="contact_message" class="required form-control"></textarea>
            </div>
          </div>
          <div class="row">
            <div class="large-12 columns">
              <input type="submit" name="contact_submit" id="contact_submit" value="SEND MESSAGE" class="button" style="color: black;">
            </div>
          </div>
        </form>

下面是我的PHP。任何有关如何使这项工作的见解都会很棒!谢谢。

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

0 个答案:

没有答案