Why doesn't this php mail script work?
I made a php script that sends mail. It worked fine until i changed it so it sent stuff as html instead of just plain text. However, it isn't working. The script itself returns a success, but I'm not getting the email. I've checked my spam folder. Could anyone see why this isn't working? Thanks
<?php
$to = $_POST["mail"];
$subject = 'Registration at Campatet';
$message = '
<html>
<head>
<title>Registration at Campatet</title>
</head>
<body>
<p>Thank you for registering at Campatet!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
&l开发者_StackOverflow社区t;/html>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: no-reply@campatet.com" . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo "Success sending e-mail to: <b>".$to."</b>";
}
else{
echo "There was a error";
}
?>
Use this as your only header:
$headers = "Content-type: text/html; From: no-reply@campatet.com";
First, try removing the line
$headers = "MIME-Version: 1.0" . "\r\n";
Are you sure that the post variable is receiving it's address correctly? Try removing that and replacing it with the email address you are trying to use.
Have you ever been able to successfully send mail from your website at all?
Specifying email headers without a Reply-To
header is often considered as reason to suspect spam. It doesn't matter that you don't want replies, just specify the Reply-To
header.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= 'From: no-reply@campatet.com' . "\r\n" . 'Reply-To: no-reply@campatet.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
精彩评论