如何将html表单发送到电子邮件

时间:2014-01-27 11:12:04

标签: php html forms email

我有这样的表格:

<form class="contact-form" method="post" action="mailto:dre4311@gmail.com">
    <p class="input-block">
        <input type="text" name="name" id="name" placeholder="Name *" />
    </p>
    <p class="input-block">
        <input type="email" name="email" id="email" placeholder="Email *" />
    </p>
    <p class="input-block">
        <button class="button turquoise submit" type="submit" id="submit"><i class="icon-paper-plane-2"></i></button>
    </p>
 </form>

我想知道,当人们填写时,我如何在电子邮件中发送相同的详细信息?

2 个答案:

答案 0 :(得分:2)

<?PHP
$email = $_POST["emailaddress"];
$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>

我希望它可以帮助你。

答案 1 :(得分:0)

试试这个方法

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Website: $website \n Message: $message";
$recipient = "YOUREMAIL@HERE.COM";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>