表格不适用于电子邮件

时间:2013-01-16 12:16:10

标签: html forms

我有一个简单的HTML表单需要发布到外部电子邮件:vynora2011@hotmail.com这样:

<form method="post" action="mailto:vynora2011@hotmail.com" ENCTYPE="text/plain">
                <label for="Name">Naam:</label>
                <input type="text" name="Name" id="Name" />

                <label for="City">Plaats:</label>
                <input type="text" name="City" id="City"  />

                <label for="Email">Email:</label>
                <input type="text" name="Email" id="Email" />

                <label for="Message">Bericht:</label>
                <textarea name="Message" rows="5" cols="20" id="Message"></textarea>

            <input type="submit" name="submit" value="Bericht verzenden" class="submit-button" />
            </form>

示例:JsFiddle

当我查看我的电子邮件时,我看不到任何消息。

1 个答案:

答案 0 :(得分:1)

你应该有一些PHP(或其他语言)。 因为我心情很好,我会为你做的。 只需复制/粘贴此代码:

  <?php 
if ($_POST["email"]<>'') { 
    $ToEmail = 'vynora2011@hotmail.com'; 
    $EmailSubject = 'Mail Subject'; 
    $mailheader = "From: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $MESSAGE_BODY = "Name: ".$_POST["name"].""; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."";
    $MESSAGE_BODY = "City: ".$_POST["city"].""; 
    $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"]).""; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>
    Your message has been send. 
    <?php 
} else { 
?>
    <form id="contato-main" action="index.php" method="post">
      <input id="name" name="name" type="text" required="required" placeholder="Naam"/>
      <input id="email" name="email" type="text" required="required" placeholder="E-Mail" />
      <input id="city" name="city" type="text" placeholder="Plaats"/>
      <textarea id="message" name="message" required="required" placeholder="Bericht></textarea>
      <br />
      <input id="submit" type="submit" name="Submit" value="Submit" />
    </form>
    <?php 
}; 
?>

当然,编辑以满足您的(CSS)需求。另外,编辑“$ EmailSubject =''中的邮件主题”即可。