我写了一个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!");
};
?>
答案 0 :(得分:1)
试试这段代码:
if(mail($emailID, $subject, $body, $headers)){
echo "<h4>Thank you for sending us an enquiry. We will get back to you.</h4>";
}
else{
echo "<h4>Mail sending fail.</h4>";
}
答案 1 :(得分:-2)
Try using \n instead of \r\n.
OR
you could use the PHP_EOL constant
OR
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Person <mail@domain.com>' . "\r\n";
$headers .= 'From: My Name <myemail@address.com>' . "\r\n";
$headers .= 'Cc: ' . "\r\n";
$headers .= 'Bcc: ' . "\r\n";