将信息从 html 表单发送到电子邮件
Sending information from html form to email
我有一个简单的网站表单,允许用户向我的客户电子邮件地址发送 query/message。
我正在努力使它正常工作。到目前为止,我已经设法找到了一些代码(也是通过堆栈溢出),允许表单在提交时将空白电子邮件发送到正确的地址。我似乎缺少一些代码或使提交按钮从表单中提取信息以发送的代码。
下面是我的代码。
谢谢(PS 我没有使用 PHP 的经验,只是为了改变我之前找到的代码才能做到这一点)。
<?php
mail('chameleonyeadon@gmail.com', $_POST['name'], $_POST['email'], $_POST['number'], $_POST['message']);
?>
<form method="post" action="email.php" enctype="text/plain">
<!-- name-->
<label class="contact__form--label"><em>What is your name?</em><br>
<input type="text" name="name" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your name here" maxlength="30" required="required"/></label><br>
<!-- email-->
<label class="contact__form--label"><em>Do you have an email address?</em><br>
<input type="email" name="email" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your email address here" maxlength="50" required="required"/></label><br>
<!-- number-->
<label class="contact__form--label"><em>Can we contact you by phone?</em><br>
<input type="number" name="number" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter a phone number we can use here" maxlength="50" required="required"/></label><br>
<!-- message-->
<label class="contact__form--label"><em>What is your message?</em><br>
<textarea name="message" required="required" class="contact__form__inputbox contact__form__inputbox--marg contact__form__textarea contact__form__inputbox--pad" placeholder="Enter your message here"></textarea></label><br>
<div class="contact__form__btns">
<input type="submit" value="Send" class="btn btn--brdr btn--padding--less">
<input type="reset" value="Clear" class="btn btn--brdr btn--padding--less btn__formpos">
</div>
</form>
首先,您必须删除 action="email.php"
,因为您将 PHP 代码放在同一个文件中。
然后,您必须删除 enctype="text/plain"
才能使其正常工作。
See this Whosebug subject
最后,除了您的 required
验证
之外,最好在执行邮件功能之前测试 PHP 中发送的内容
我有一个简单的网站表单,允许用户向我的客户电子邮件地址发送 query/message。
我正在努力使它正常工作。到目前为止,我已经设法找到了一些代码(也是通过堆栈溢出),允许表单在提交时将空白电子邮件发送到正确的地址。我似乎缺少一些代码或使提交按钮从表单中提取信息以发送的代码。
下面是我的代码。
谢谢(PS 我没有使用 PHP 的经验,只是为了改变我之前找到的代码才能做到这一点)。
<?php
mail('chameleonyeadon@gmail.com', $_POST['name'], $_POST['email'], $_POST['number'], $_POST['message']);
?>
<form method="post" action="email.php" enctype="text/plain">
<!-- name-->
<label class="contact__form--label"><em>What is your name?</em><br>
<input type="text" name="name" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your name here" maxlength="30" required="required"/></label><br>
<!-- email-->
<label class="contact__form--label"><em>Do you have an email address?</em><br>
<input type="email" name="email" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your email address here" maxlength="50" required="required"/></label><br>
<!-- number-->
<label class="contact__form--label"><em>Can we contact you by phone?</em><br>
<input type="number" name="number" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter a phone number we can use here" maxlength="50" required="required"/></label><br>
<!-- message-->
<label class="contact__form--label"><em>What is your message?</em><br>
<textarea name="message" required="required" class="contact__form__inputbox contact__form__inputbox--marg contact__form__textarea contact__form__inputbox--pad" placeholder="Enter your message here"></textarea></label><br>
<div class="contact__form__btns">
<input type="submit" value="Send" class="btn btn--brdr btn--padding--less">
<input type="reset" value="Clear" class="btn btn--brdr btn--padding--less btn__formpos">
</div>
</form>
首先,您必须删除 action="email.php"
,因为您将 PHP 代码放在同一个文件中。
然后,您必须删除 enctype="text/plain"
才能使其正常工作。
See this Whosebug subject
最后,除了您的 required
验证