Problems sending HTML emails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Problems sending HTML emails

Post by mzfp2 »

Hi All,

I've just copied a newsletter script I've been running for a while from my previous host to a new host and ran into a problem.

Emails are being received as texts rather than HTML, (didn't have this problem on my previous host), I dont if the problem is related toi the fact that my new host adds some text to the email itself .. Here's what I receive in my inbox :



Content-Type: text/html

Message-Id: <E1DD3Jq-0006bs-00@venus.webfusion.co.uk>
Date: Sun, 20 Mar 2005 16:30:26 +0000

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head>

<body>
Newsletter
<img src="http://stopandshop.me.uk/news/images/test.jpg" width="120" height="200" />
</body>
</html>


Message-ID and Date appear because the host seems to be writing this to every email.

Is there any way to force the email to be a html email?

Kind Regards
Musaffar
http://www.good2shop.co.uk
Last edited by mzfp2 on Sun Mar 20, 2005 10:36 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post the code that generates this email
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

The code is as follows

Code: Select all

$subject = 'Stop&Shop Nesletter';
      $message = ParseTemplate($template, $ent);
      $to      = $row[email];
      $xtra    = "From: info@stopandshop.me.uk (StopAndShop)\r\n";
      $xtra   .= "Content-Type: text/html \r\n";
      $mail_result = @mail($to, $subject, $message, $xtra);

However I doubt it has much to do with the code, as this code worked perfectly on my previous host.

Kind Regards
Musaffar
http://www.good2shop.co.uk
Last edited by mzfp2 on Sun Mar 20, 2005 10:39 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try removing the trailing line-feed and carriage return in your header data.
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

I've removed the

Code: Select all

\r\n
from the header data in both lines, now i get the following text in my email

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head>

<body>
Newsletter
<img src="http://stopandshop.me.uk/news/images/test.jpg" width="120" height="200" />
</body>
</html>

But not displaying as HTML :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I didn't say from both lines.. only the last one, the content-type one..
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

Hi Sorry I shoud've mentioned earlier that I have already tried removing the the carriage return and linefeed from the content-type data, to no avail.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post the full source of the email.. headers and all..
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

Headers are


Return-Path: <stopshop@venus.webfusion.co.uk>
Delivered-To: admin@alljammin.com
Received: (qmail 29072 invoked from network); 20 Mar 2005 16:36:27 -0000
Received: from venus.webfusion.co.uk (212.67.202.12)
by 0 with SMTP; 20 Mar 2005 16:36:27 -0000
Received: from stopshop by venus.webfusion.co.uk with local (Exim 3.36 #1)
id 1DD3PX-0006wY-00
for admin@alljammin.com; Sun, 20 Mar 2005 16:36:19 +0000
To: admin@alljammin.com
Subject: Stop&Shop Nesletter
From: info@stopandshop.me.uk (StopAndShop)


email code is :

Content-Type: text/html

Message-Id: <E1DD3PX-0006wY-00@venus.webfusion.co.uk>
Date: Sun, 20 Mar 2005 16:36:19 +0000


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
Newsletter
<img src="http://stopandshop.me.uk/news/images/test.jpg" width="120" height="200" />
</body>
</html>




Obtained this from Outlook. Hope it helps
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that looks like the old one... it would appear you are getting a double line break after your From attribute. Tried using just \n ?
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

Thanks, thats solved the problem, many thanks for your help :)

Musaffar
http://www.good2shop.co.uk
Post Reply