【发布时间】:2015-12-13 10:00:54
【问题描述】:
我尝试了几个版本的 php 表单邮件程序,但无法让它们中的任何一个工作。我试图让它在哪里,当用户点击“提交”时,表单上的信息会自动发送/填充到电子邮件中。目前,没有发送电子邮件,它停留在黑色网站 xxxx.com/contact.php 上。即使在阅读了许多其他类似的帖子之后,我也一直在尝试解决这个问题一周但无济于事
这是我的 html 表单:
<form method='post' action='contact.php'>
<br>
<br>
<br>
<br>
<h2>
Contact Us Form
</h2>
<table>
<tr>
<td>
<p>
Fill out the form below with your contact information and questions/comments and click submit.
We will respond to your inquiry as soon as possible via email. If you prefer a different contact
method then please provide required information and notate your preference in the comments section.
I look forward to providing you and your family with great memories that last a lifetime.
</p>
</td>
</tr>
</table>
<br>
<br>
<label>
Your name:<br>
</label>
<input type="text" name="customername" size='40' maxlength='50' required><br>
<label>
Your Email:<br>
</label>
<input type='email' name='emailaddress' size='20' maxlength='254' required><br>
<label>
Your phone number (example: 555-555-1234):<br>
</label>
<input name='telephone' type='tel' size=3>-<input type='tel' size=3>-<input type='tel' size=4><br>
<label>
What product are you interested in?<br>
</label>
<input type='radio' name='newshoot' value='new'>New Photo Shoot
<input type='radio' name='existingshoot' value='existing'>Existing Photo Shoot
<input type='radio' name='prints' value='prints'>Interested in prints
<label>
Street Adress:<br>
</label>
<input type="text" name="streetaddress" size='40' maxlength='50'><br>
<label>
City:<br>
</label>
<input type="text" name="city" size='40' maxlength='50'><br>
<label>
State:<br>
</label>
<input type="text" name="state" size='40' maxlength='50'><br>
<label>
Zipcode:<br>
</label>
<input type="text" name="zipcode" size='40' maxlength='50'><br>
<label>
What country are you located in?<br>
</label>
<select>
<option value="USA">United States</option>
<option value="AFG">Afghanistan</option>
</select><br>
<label>
Comments:<br>
</label>
<textarea name='customercomment' rows='5' cols='60' text-align='left' wrap='hard'>
在此处输入您的 cmets
<input type='submit' name='submit' value='Send' />
<input type='reset' value='Reset'/>
</form>
这是我的 php:
<?php
$email_to = "XXXXca@XXXXXto.com";
$email_subject = "Inquiry from: "($customername);
$first_name = $_POST['customername'];
$email_from = $_POST['emailaddress'];
$telephone = $_POST['telephone'];
$newshoot = $_POST['newshoot'];
$existingshoot = $_POST['existingshoot'];
$prints = $_POST['prints'];
$streetaddress = $_POST['streetaddress'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$comments = $_POST['customercomment'];
$email_message = "Form details below.\n\n".
"Customer Name: ($customername).\n Email: ($email_from).\n Telephone: ($telephone).\n New Shoot? ($newshoot).\n Existing Shoot? ($existingshoot).\n Prints? ($prints).\n Customer's address: ($streetaddress)($city)($state)($zipcode).\n Comments:($comments).\n";
if ($_POST['submit'])
{
mail($email_to, $email_subject,$email_message, $email_from) {
header('Location: index.html');
}
}
?>
【问题讨论】:
-
什么是
mail($email_to, $email_subject,$email_message, $email_from) {看起来你错过了那里的if。使用错误报告.. -
首先,为什么
header()周围有大括号?您是否不小心忘记添加if?另外,您的$email_from是否包含"From: "?检查这两个。另外,您的错误日志是否包含任何错误? -
$email_from = $_POST['emailaddress'];不,它没有。 if ($_POST['submit']) { if mail($email_to, $email_subject, $email_message, $email_from) header('Location: index.html');我改变了这个以添加'if'并取出 {} 周围的标题,仍然无法正常工作。非常菜鸟的问题。你指的是什么错误日志?
-
在提交之前显示很多错误。在发送电子邮件之前,首先检查表单提交时所有数据是否正确接收。如果所有数据都正确恢复,则使用邮件功能。并使用复选框而不是单选按钮并使用 if(isset($_post['submit'])){enclosure all form data
标签: php html forms email form-submit