1

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>
</html>
';

$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

$headers .= "From: [email protected]" . "\r\n";

if(mail($to, $subject, $message, $headers)){
echo "Success sending e-mail to: <b>".$to."</b>";
}
else{
echo "There was a error";
}
?>
3
  • Have you take into account ob_start and ob_get_clean? Commented Aug 4, 2011 at 3:20
  • Have a look through php.net/manual/en/function.mail.php and see if you have forgotten something perhaps? Commented Aug 4, 2011 at 6:10
  • If you're on UNIX and using localhost as a mail server, take a look at the mail log to see if there are any errors. Commented Aug 4, 2011 at 18:26

3 Answers 3

2

Use this as your only header:

$headers  = "Content-type: text/html; From: [email protected]";
Sign up to request clarification or add additional context in comments.

1 Comment

it's this that is preventing me from getting the e-mail:Content-type: text/html; I remove that, and it sends successfully
1

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?

5 Comments

and I have commented out that $headers = "MIME-Version: 1.0" . "\r\n"; before. did nothing. And it is receiving the e-mail address correctly. If you lookat the bottom, it echos the address
Just create another page for testing. To test it, take out all of the html and then put just a few words. Then take out the content type line and take out the . \r\n after the from. Be sure to remove the period before the equal sign on the from line, too.
I took out all the headers except for the from part, changed to content to "hi", and I immediately received the mail. I wonder why this is happening
ok, it's this line that is stopping the whole thing from working: $headers = "Content-type: text/html; charset=iso-8859-1" . "\r\n"
Does the html display properly if you remove it?
1

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: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.