html e-mails from mail()

This is a discussion on html e-mails from mail() within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I've been using a function that uses mail() to try ant send a html e-mail, with little sucess - ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-02-2004
Dafydd Monks
 
Posts: n/a
Default html e-mails from mail()

I've been using a function that uses mail() to try ant send a html e-mail,
with little sucess - the html displays as plaintext in the e-mail body.

I know about MIME, but I'm not really sure how to implement it in PHP
without using a pipe to sendmail.

Is there a good tutorial on the net - I've looked, but can only find e-books
and the like and I need a tutorial that's short and to the point.

Cheers,

Dave.


Reply With Quote
  #2 (permalink)  
Old 08-03-2004
Dafydd Monks
 
Posts: n/a
Default Re: html e-mails from mail()

Problem solved - I've found out that it's best to have the headers as strigs
in the mail() command it's self - variables don't seem to work well.

Cheers,

David.

"Dafydd Monks" <dafydd.monks@dragondesigns.org.uk> wrote in message
news:cemc4d$rsn$1@newsg4.svr.pol.co.uk...
> I've been using a function that uses mail() to try ant send a html e-mail,
> with little sucess - the html displays as plaintext in the e-mail body.
>
> I know about MIME, but I'm not really sure how to implement it in PHP
> without using a pipe to sendmail.
>
> Is there a good tutorial on the net - I've looked, but can only find

e-books
> and the like and I need a tutorial that's short and to the point.
>
> Cheers,
>
> Dave.
>
>



Reply With Quote
  #3 (permalink)  
Old 08-03-2004
eclipsboi
 
Posts: n/a
Default Re: html e-mails from mail()

$from = "me@mydomain.com";
$username = "Georgey Porgey";
$email = "pudding@pie.com";
$message = "This is a bold-face test!";

$headers = "MIME-Version: 1.0\r\n"
. "Content-type: text/html; charset=iso-8859-1\r\n"
. "To: $username <$email>\r\n"
. "From: $from\r\n"
. "X-Mailer: PHP " . phpversion() . "\r\n"
. "Reply-to: $from";

$body =<<<END
<html>
<head>
<style type="text/css" media="screen">
..test { font-weight: bolder; }
</style>
</head>
<body>
<span class="test">$message</span>
</body>
</html>
END;

$sendmailargs = "-f " . $from;

if (mail('', $subject, $body, $headers, $sendmailargs))
{
print("Successful email sent");
}
else
{
print("Poo, email didn't send.");
}

Minus some minor details--factual email addresses namely--the code
above works perfectly every time, and you can see I'm using variables
all over the place. Now, one thing I did have a problem with is my
sendmail being set up and running correctly--imagine my surprise on
the very day I got sendmail configured correctly I start getting test
mail()'s I tried sending last year--but didn't have the time to track.
;)

Oh, and before I forget, if you supply a To header, don't put anything
for the first arguement of mail(), and vice versa.

On Tue, 3 Aug 2004 00:01:44 +0100, "Dafydd Monks"
<dafydd.monks@dragondesigns.org.uk> wrote:

>Problem solved - I've found out that it's best to have the headers as strigs
>in the mail() command it's self - variables don't seem to work well.
>
>Cheers,
>
>David.
>
>"Dafydd Monks" <dafydd.monks@dragondesigns.org.uk> wrote in message
>news:cemc4d$rsn$1@newsg4.svr.pol.co.uk...
>> I've been using a function that uses mail() to try ant send a html e-mail,
>> with little sucess - the html displays as plaintext in the e-mail body.
>>
>> I know about MIME, but I'm not really sure how to implement it in PHP
>> without using a pipe to sendmail.
>>
>> Is there a good tutorial on the net - I've looked, but can only find

>e-books
>> and the like and I need a tutorial that's short and to the point.
>>
>> Cheers,
>>
>> Dave.
>>
>>

>


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:07 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0