我可以帮你吗?我已经为我妈妈的业务制作了一个带文本输入框的简单html表,我想通过电子邮件发送它们,所以我制作了一个PHP脚本,但它从不发送电子邮件。我的服务器上有很多简单的表单可以正常工作,但我使用的是html表单,所以很容易。但是我无法弄清楚代码出了什么问题; php脚本触发并收到确认消息并重定向到我的菜单但没有电子邮件。我简化了我的代码,因此它只有一个表行和一个下拉框和两个文本输入框。请有人能告诉我我的错误的解决方案吗?我有PHP的基本知识。
这是我网站的链接"它的基本"我坚持的形式是租金形式,其余工作正常。 http://www.edwinswebsite.co.uk/index.html
<!DOCTYPE html>
<!--
edwin martin
27/06/2016
V1
-->
<html lang="en">
<head>
<!-- ensures the document is using the correct char set -->
<meta charset="utf-8">
<meta name="description" content="a quick description of the page goes here">
<title>payment form</title>
<link rel="stylesheet" href="styles/style.css">
<!--
The below section looks like a comment, but it's a conditional include statement.
It's ignored by all browsers except IE9. html5shiv is a library that fixes some HTML5
IE bugs.
-->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style type="text/css">
</style>
</head>
<body>
<div id="wrapper">
<h1 class="red">Proof of Payment Form</h1>
<table>
<caption>
<select size="1" name="cf_drop_down" class="drop">
<option value=" Not selected">Select Address</option>
<option value=" 2 Some rd">2 Some rd</option>
<option value=" 6 Other rd">6 Other rd</option>
<option value=" 7 More rd">7 More rd</option>
<option value=" 19 More rd">19 More rd</option>
<option value=" 38 More rd">38 More rd</option>
<option value=" 54 Forth rd">54 Forth rd</option>
<option value=" 72 Fifth ave">72 Fifth ave</option>
<option value=" 77 Fifth ave">77 Fifth ave</option>
<option value=" 99 Fifth ave">99 Fifth ave</option>
</select>
</caption>
<tr>
<th> Student 1 Name</th>
<th> Student 2 Name </th>
<th> Student 3 Name </th>
<th> Student 4 Name </th>
<th> Student 5 Name </th>
<th> Student 6 Name </th>
<th> Student 7 Name </th>
</tr>
<tr>
<td><input type="text" value="test" name="cf_name1"></td>
<td><input type="text" value="test" name="cf_name2"></td>
<td><input type="text" value=""></td>
<td><input type="text" value=""></td>
<td><input type="text" value=""></td>
<td><input type="text" value=""></td>
<td><input type="text" value=""></td>
</tr>
<input type="button" value="Send" class="submit_button" onclick="location.href='payment.php'" method="post">
<input type="button" value="Menu" class="submit_button" onclick="location.href='index.html'">
</table>
</div>
</body>
</html>
PHP代码
<?php
$field_name = $_POST['cf_name1'];
$field_name2 = $_POST['cf_name2'];
$drop_down_item = $_POST['cf_drop_down'];
$mail_to = 'xxxx@example.com, xxxxx@example.com';
$subject = 'Message from me '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_name2."\n";
$body_message .= 'Address: '.$drop_down_item."\n";
$headers = 'From: '.$field_name."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to xxxx@example.com');
window.location = 'index.html';
</script>
<?php
}
?>
答案 0 :(得分:0)
好的,我现在只需在表格中放置一个表单标签,我的php工作正常