0

I'm trying to send emails to my website members using the mail() function with PHP,

The mails are in hebrew, and I want to send an html email,

That's pretty much how I send it

$mail_to = "Email@domain.com";
$message = "
<html>
some content here
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=windows-1255" . "\r\n";
$headers .= 'From: "MyWebsiteName" <support@domain.com>' . "\r\n";

$mail = mail($mail_to, $subject, $message, $headers );

It works completely fine with clients such as Gmail, or thunderbird users, but I viewed it in a few other clients, that aren't so famous, but still widely used in my country, and it just shows me the html source.. I'll also add that I've seen other mails in those clients that are working fine, so they are supporting html mails.

What am I doing wrong?

Edit:

I viewed the headers, and it's weird, these are their headers:

MIME-version: 1.0
X-Mailer: aspNetEmail ver 4.0.0.6
Content-type: text/html; charset=UTF-8

Content-transfer-encoding: quoted-printable
SLNG_REVERSE_PATH: mail@domain.co.il
DT: 2
DB: 1
QueueCmd: 1
List-Unsubscribe: <mailto: mail@domain.co.il>
Original-recipient: rfc822;myemail@domain.com

These are mine:

Message-id: <20120913143702.10413.qmail@www022.inter.co.il>
MIME-version: 1.0
Content-type: TEXT/PLAIN
Content-transfer-encoding: 8BIT
Original-recipient: rfc822;myemail@domain.com

Content-type:text/html;charset=windows-1255

It's like they added TEXT/PLAIN to mine for some reason, how come?

Radicate
  • 2,934
  • 6
  • 26
  • 35
  • 1
    I'd have a good look at one of the emails that is showing up as HTML in the other clients, specifically at the headers. Is there something in there that you're not including? Are you formatting your headers in the same way? – andrewsi Sep 13 '12 at 15:42
  • That depends on the client. You'll need to see the full internet headers for one of the emails - just google for 'view headers' and 'name of email client' should do the trick. – andrewsi Sep 13 '12 at 15:44
  • @andrewsi I made it to view the headers, it's really odd, I edited my question, look there :) – Radicate Sep 13 '12 at 15:56
  • don't use php's build in `mail()` function. It's not fit for purpose, beyond the most very basic text-only email. I strongly recommend using the phpMailer class instead. See also my answer here: http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail/12302354#12302354 – SDC Sep 13 '12 at 15:58
  • @Don - Has it also dropped the `From:` line? Or did you just not include that line? – andrewsi Sep 13 '12 at 16:00
  • @andrewsi it included the From line as well, but not exactly as I passed it before. it only showed the email address I provided, but not the contact name ("MyWebsiteName") – Radicate Sep 13 '12 at 16:03
  • When you email yourself and it shows up as HTML, are you getting that same header in gmail? – andrewsi Sep 13 '12 at 16:05
  • @andrewsi In the places I can see it as HTML the headers seem better, I see the exact same From header, also there's no addition of TEXT/PLAIN in them, one of them was Gmail – Radicate Sep 13 '12 at 16:08
  • What happens if you send the same email to yourself at Gmail, and CC the client? Are the headers the same then? – andrewsi Sep 13 '12 at 16:09
  • @andrewsi What do you mean? shall I send it through PHP again, and add a cc to the other email that doesn't display it correctly? – Radicate Sep 13 '12 at 16:12
  • @Don - yes, please. That way, both emails should have the same headers set, so if they're different when they arrive, you know that the problem lies elsewhere. – andrewsi Sep 13 '12 at 16:13
  • @andrewsi Just did that, it works fine on Gmail again, but not on the other client, again, I know that theres something wrong with this client, but I really wanted to support it, I thought that there was something I could do to make it fit to it as well, like others did and obviously succeeded – Radicate Sep 13 '12 at 16:16
  • @Don - Are the headers the same in both? – andrewsi Sep 13 '12 at 16:16
  • @andrewsi Nope, in that client I can see these headers added before mine: MIME-version: 1.0 Content-type: TEXT/PLAIN Content-transfer-encoding: 8BIT – Radicate Sep 13 '12 at 16:18
  • Have a look at ontrack's answer - it looks like you might be getting an extra line break in the headers you're adding. – andrewsi Sep 13 '12 at 16:21
  • @andrewsi I see, does some space before the mail() function in the file matter? or just the spaces in the headers variable? – Radicate Sep 13 '12 at 16:24
  • It should just be in the headers variable. Try putting your `Content-type` header first and see... – andrewsi Sep 13 '12 at 16:25
  • @andrewsi :) finally I can see some html, it looks fine, although now in the page itself I see : MIME-Version: 1.0 :x – Radicate Sep 13 '12 at 16:28
  • There's an issue in your code generating `$headers` - maybe try using just '\n' at the end? – andrewsi Sep 13 '12 at 16:36
  • @andrewsi Is it a must to provide the Mime version? – Radicate Sep 13 '12 at 16:36
  • @andrewsi I removed the \r from the headers and simply used \n, it all seems to be working great now, thank you so much! – Radicate Sep 13 '12 at 16:47

5 Answers5

2

After your edit:

You've got a line-break too many before your Content-type header, which makes it part of the body of an email. Some clients will detect this erroneous format or recognize the HTML content. Others will assume text/plain or a mail-server will add the text/plain header itself because it thinks you haven't specified any.

ontrack
  • 2,963
  • 2
  • 15
  • 14
0

From my POV - nothing. If you read HTML, it's because the client cannot read a content-type of text/html. My solution ? Create a multi-part email and include both text/html and text/plain. If you want, save your email inside a webpage. When you are sending the text/html, send it as you do. Using the text/plain, send a link to the webpage where you store the email.

Also, try adding space like that:

Content-type: text/html; charset=windows-1255

Not sure it will change something but whom knows. By the way, the concatenation isn't useful in here.

David Bélanger
  • 7,400
  • 4
  • 37
  • 55
  • As I said, I received some html emails using these clients I spoke about and they looked fine, only my email doesn't pass as an html email, it thinks it's a plain text email for some reason – Radicate Sep 13 '12 at 15:41
  • I understand, but try to send both as a multipart email to see what is the results - also read the headers in the mail client. – David Bélanger Sep 13 '12 at 15:44
  • I viewed the headers and I edited my question, please have a look – Radicate Sep 13 '12 at 15:58
0

try Content-type: text/html; charset="iso-8859-8"

Teena Thomas
  • 5,139
  • 1
  • 13
  • 17
0

I would strongly suggest not using PHP's mail() function. It's not fit for purpose, unless you're doing really basic stuff like sending a simple text-only message to a single address.

For anything even slightly more complex, I suggest using the phpMailer class.

phpMailer makes it very easy to work with complex emails in PHP. It handles HTML messages, attachments, multiple recipients, and a bunch of other features, all in a very simple and easy to use API.

See also another answer I wrote previously for more details: Send attachments with PHP Mail()?

Community
  • 1
  • 1
SDC
  • 14,192
  • 2
  • 35
  • 48
0

because is in hebrew you may try:

$headers .= "Content-Type: text/html; charset=utf-8\r\n";

i use this in greek mailings

than107
  • 33
  • 4