我希望有人能用我的联系表格(HTML& PHP)帮助我。收到的电子邮件中未附带“公司名称”字段。所有其他字段都可以正常工作。
这是我的HTML表单代码:
<form action="contact.php" method="post">
Company Name<br>
<input type="text" name="cf_company" size="60">
<span class="contact"><img src="images/AIS Logo New.png" alt="AIS logo" width="325" height="170" hspace="25" align="right" class="contactimage"></span><br><br>
Contact Name<br>
<input type="text" name="cf_name" size="60">
<br><br>
Email<br>
<input type="text" name="cf_email" size="60">
<br><br>
Phone Number<br>
<input type="text" name="cf_phone" size="60">
<br><br>
State<br>
<input type="text" name="cf_state" size="60">
<br><br>
Sic Code<br>
<input type="text" name="cf_sic" size="60">
<br><br>
Total # of Employees<br>
<input type="text" name="cf_employees" size="60">
<span class="contact"><img src="images/People_image.jpg" alt="AIS logo" width="274" height="177" hspace="25" align="right" class="contactimage"></span><br><br>
Current Carrier<br>
<input type="text" name="cf_carrier" size="60">
<br><br>
Present Experience Mod<br>
<input type="text" name="cf_experience" size="60"><br><br>
Are you presently in the Assigned Risk Pool?<br>
<input name="cf_pool" type="text" size="60">
<br><br>
Comments/Additional Information<br>
<textarea name="cf_message" cols="75" rows="8"></textarea><br><br><br>
<center><input type="submit" value="Send">
<input type="reset" value="Clear">
这是我的PHP代码:
<?php
$field_company = $_POST['cf_company'];
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_phone = $_POST['cf_phone'];
$field_state = $_POST['cf_state'];
$field_sic = $_POST['cf_sic'];
$field_employees = $_POST['cf_employees'];
$field_carrier = $_POST['cf_carrier'];
$field_experience = $_POST['cf_experience'];
$field_pool = $_POST['cf_pool'];
$field_message = $_POST['cf_message'];
$mail_to = 'xxxxxxx@aol.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_company."\n";
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'State: '.$field_state."\n";
$body_message .= 'Sic: '.$field_sic."\n";
$body_message .= 'Employees: '.$field_employees."\n";
$body_message .= 'Carrier: '.$field_carrier."\n";
$body_message .= 'Experience: '.$field_experience."\n";
$body_message .= 'Pool: '.$field_pool."\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 the message. We will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to xxxxxxxxx@aol.com');
window.location = 'contact.html';
</script>
<?php
}
?>
* *以下是我收到的电子邮件反馈(减去公司名称信息)
来自:金佰利 电子邮件:xxxxxx@aol.com 电话:909-xxx-xxxx 州:CA Sic:45677 员工:35 承运人:没有 经验:没有 游泳池:没有 消息:TEST
答案 0 :(得分:1)
$body_message = 'From: '.$field_company."\n";
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
第二行会覆盖$ body_message已包含的内容。
如果你想追加到变量,你也必须在那里使用.=
。
答案 1 :(得分:0)
第二行......需要这样
$ body_message。='From:'。$ field_name。“\ n”;
您错过了连接运算符