【发布时间】:2014-06-13 04:29:04
【问题描述】:
我写了一个 php 脚本,它将表单中的数据保存在 mysql 数据库中,然后发送电子邮件。数据保存在数据库中,并发送了电子邮件,但我没有在收件箱中收到它。我是 php 新手,不知道是什么原因造成的。请帮忙。
<?php
include ('regdb_conn.php');
if (isset($_POST['submit'])){
$companyname = $_POST['companyname'];
$pAddress = $_POST['pAddress']; // required
$lAddress = $_POST['lAddress']; // required
$telno4 = $_POST['telno4']; // required
$faxno4 = $_POST['faxno4']; // required
$email4 = $_POST['email4'];
$trade = $_POST['trade'];
$business = $_POST['business'];
$noEmployee = $_POST['noEmployee'];
$designation = $_POST['designation'];
$hr = $_POST['HR'];
$retainer_fee_1 = $_POST['retainer_fee_1'];
$retainer_fee_2 = $_POST['retainer_fee_2'];
$from_date = $_POST['from_date'];
$to_date = $_POST['to_date'];
$sql="INSERT INTO subscription(company_name,postal_address,location_address,
telephone,fax,email,trade_union_workmen,nature_of_business,total_employee,
details_newsletter,name_head_hr,retainer_fee_1,retainer_fee_2,from_date,to_date)
VALUES('$companyname','$pAddress','$lAddress','$telno4','$faxno4','$email4',
'$trade','$business','$noEmployee','$designation',
'$hr','$retainer_fee_1','$retainer_fee_2','$from_date','$to_date')";
$result = mysql_query($sql);
if($result) {
echo "Data Successfully saved in database subscription!";
}
else {
echo "ERROR, data was not saved or email was not sent";
}
$emailID = "suthan47@outlook.com";
$subject = "New Subcription form submitted from. $companyname . through our website";
$body = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
<tbody>
<tr>
<td style="padding: 5px 10px;" width="150">Company Name: </td>
<td style="padding: 5px 10px;">$companyname</td>
</tr>
<tr>
<td style="padding: 5px 10px;" width="150">Telephone No: </td>
<td style="padding: 5px 10px;">$telno4</td>
</tr>
<tr>
<td style="padding: 5px 10px;" width="150">Email: </td>
<td style="padding: 5px 10px;">$email4</td>
</tr>
<tr>
<td style="padding: 5px 10px;" width="150">Fax No: </td>
<td style="padding: 5px 10px;">$faxno4</td>
</tr>
</tbody>
</table>
EOD;
$headers = "From:" .$email4. "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
mail($emailID, $subject, $body, $headers );
echo "<h4>Thank you for sending us an enquiry. We will get back to you.</h4>";
} else {
echo("Kindly use the form to submit the data!");
};
?>
【问题讨论】:
-
检查到垃圾邮件文件夹?
-
还要检查邮件是否真的发送
if( mail($emailID, $subject, $body, $headers ) ) {echo "sent";} -
@UserProg 你是对的.. 我就是这么想的。
-
网站托管在哪里?本地主机?在线某处?
-
您如何知道邮件已发送?您必须设置一个条件来检查邮件是否实际发送。
标签: php mysql email html-email