0

I am trying to send html email using php. it is working fine on gmail, yahoo etc. but on my cpanel (Horde Email Client) the text is comming as an attachment and it is not showing any body.

These are the headers i am using

   $headers = "From: " ."XYZ<[email protected]>" . "\r\n";
   $headers .= "Reply-To: ". "[email protected]" . "\r\n";
   $headers .= "MIME-Version: 1.0" . "\r\n";
   $headers .= "Content-type:text/html;charset=us-ascii" . "\r\n";

I have also tried changing the charset to iso-8859-1 but still no sucess

6
  • Maybe your cpanel does not accept html emails for security? Just a thought... Commented Feb 11, 2012 at 2:09
  • Now i removed the headers and sent again this time email got recieved as a plain text. but i want html formating ?? am i doing anything wrong in my headers ? Commented Feb 11, 2012 at 2:17
  • I think it has to do with your cpanel settings then... Commented Feb 11, 2012 at 2:18
  • just for fun, try doing $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; first and then the rest of your headers (minus the last two you have listed) Commented Feb 11, 2012 at 2:22
  • 1
    Yes to the comments about using a library. There is no value trying to do this oneself. +1, +1 Commented Feb 11, 2012 at 21:21

2 Answers 2

3

Sending emails is hard, and fraught with serious security problems (mostly related to spam). It takes years to write code that sends email reliably.

Instead of trying to do it yourself, this is a place where a third party library makes sense.

We have been using PHPMailer for years: http://code.google.com/a/apache-extras.org/p/phpmailer/

Sign up to request clarification or add additional context in comments.

Comments

3

It is difficult to write custom code that sends HTML e-mail, especially ones with embedded images or attachments. I have written a class to do this, but once you do, you realise there are a bunch of other features you need.

Using a third-party library really is a better choice here if your core product is not a mailing library. PHPMailer is good, another good option is

swiftmailer

Good luck!

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.