我有一个当前正在工作的表单,但想将 php 代码添加到“发布”文件中,因此需要 html 表单中的某些字段,否则会显示一条消息。
继承人我的 html 代码此刻。
<form action="contact.php" method="post">
<input type="text" class="main" name="cf_name" value="Name (Required)" size="31" />
<br />
<br />
<input type="text" class="main" name="cf_company" value="Company" size="31" />
<br />
<br />
<input type="text" class="main" name="cf_phone" value="Phone (Required)" size="31" />
<br />
<br />
<input type="text" class="main" name="cf_email" value="Email (Required)" size="31" />
<br />
<br />
<textarea type="text" name="cf_text0" cols="34" rows="3" class="main">Message</textarea>
<br />
<input type="image" src="images/send.jpg" height="16" width="41" border="0"
alt="Submit Form" />
</form>
这是我的php代码
<?php
$field_name = $_POST['cf_name'];
$field_company = $_POST['cf_company'];
$field_phone = $_POST['cf_phone'];
$field_email = $_POST['cf_email'];
$field_message = array($_POST["cf_text0"],);
$mail_to = 'callum@colmandesigns.co.nz';
$subject = 'A & J Print - Contact Form '.$field_name;
$field_message="From: {$field_name}
Company: {$field_company}
Phone: {$field_phone}
Email: {$field_email}
Message: {$field_message[0]}";
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $field_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 craig@colmandesigns.co.nz');
window.location = 'index.html';
</script>
<?php
}
?>
我想要填写姓名、电话和电子邮件字段。
谢谢,卡勒姆