我为具有多个字段的网站创建了联系表单。清除按钮工作正常,但是当我单击“提交”按钮时,我无意中下载了与网页关联的.php文件,而不是将包含订单的电子邮件发送到指定的地址。我在这里真的很新,所以任何帮助都会非常感激。
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_quantity = $_POST['cf_quantity'];
$field_which = $_POST['cf_which'];
$field_size = $_POST['cf_size'];
$field_school = $_POST['cf_school'];
$field_college = $_POST['cf_college'];
$field_message = $_POST['cf_message'];
$mail_to = 'xxx@gmail.com';
$subject = 'TShirt Order - xxx.Org '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail Address: '.$field_email."\n";
$body_message .= 'Quantity of Shirts: '.$field_quantity."\n";
$body_message .= 'Shirt Style(s): '.field_which."\n";
$body_message .= 'Size(s): '.field_size."\n";
$body_message .= 'School: '.field_school."\n";
$body_message .= 'College: '.field_college."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for placing an order with xxx.Org. We will contact you shortly.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to xxx@gmail.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
html代码是:
<form action="contact.php" method="post">
Full Name:
<input type="text" name="cf_name">
<br />
<br />
Email Address:
<input type="text" name="cf_email">
<br />
<br />
Quantity of TShirts:
<input type="numeric" name="cf_quantity">
<br />
<br />
Which Style(s)?
<input type="text" name="cf_which">
<br />
<br />
Size(s):
<input type="text" name="cf_size">
<br />
<br />
Name of School:
<input type="text" name="cf_school">
<br />
<br />
Name of College:
<input type="text" name="cf_college">
<br />
<br />
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
答案 0 :(得分:1)
你完全确定服务器是否接受php?接缝给我服务器不明白它应该使用php interpeter而不是激活php命令它只是让你下载文件。
如果您不确定尝试使用简单文件制作文件,请调用该文件并查看其是否有效。
最好的问候,
标记