Re: Send HTML email
| From: | Comron E Sattari | Date: | Fri, 30 Jun 2000 09:04:26 +0000 |
| Subject: | Re: Send HTML email | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3988@lists.php.net to get a copy of this message | ||
I had to send an html email and I did the following:
$bondaryAlternative = md5(uniqid(""));
$bondaryRelated = md5(uniqid(""));
$headerini = "X-Mailer: $mailer\nReturn-Path: $email \nFrom: $from";
$header = $headerini."\nMIME-Version: 1.0";
$header .= "\nContent-Type: multipart/alternative;
boundary=\--------------$bondaryAlternative\"";
$header .= "\nContent-Transfer-Encoding: 7bit";
$startbodytext = "\n\n\n--------------".$bondaryAlternative;
$startbodytext .= "\nContent-Type: text/plain;";
$startbodytext .= "\nContent-Transfer-Encoding: 7bit\n\n";
$startbodyhtml = "\n\n\n--------------".$bondaryAlternative;
$startbodyhtml .= "\nContent-Type: multipart/related;";
$startbodyhtml .= " boundary=\"------------".$bondaryRelated."\"";
$startbodyhtml .= "\n\n\n--------------".$bondaryRelated;
$startbodyhtml .= "\nContent-Type: text/html; charset=us-ascii ";
$startbodyhtml .= "\nContent-Transfer-Encoding: 7bit\n\n";
$endbody = "\n\n--------------".$bondaryRelated."--";
$endbody .= "\n\n--------------".$bondaryAlternative."--";
$fp = fopen("./htmlemail.file", "r");
$message = fread($fp, filesize ("./htmlemail.file"));
fclose($fp);
$fd = fopen("./textemail.file", "r");
$textmessage = fread($fd, filesize ("./textemail.file"));
fclose($fd);
$body = $startbodytext;
$body .= byte7encode($textmessage);
$body .= $startbodyhtml;
$body .= $message;
$body .= $endbody;
mail($to, $title, $body, $header);
and byte7encode is:
function byte7encode($string){
$string = ereg_replace("=", "=3D", $string) ;
$ret_string="";
$len=strlen($string);
for($x=0;$x<$len;$x++){
$char=substr($string, $x, 1);
$ord = ord($char) ;
if ($ord>127) {
$ret_string .= strtoupper("=".dechex($ord));
} else {
$ret_string .= $char ;
}
}
return $ret_string;
}
Comron
PS. Thanks to Joao, and Philippe.
----- Original Message -----
From: "Bernie Huang" <bernie.huang@ec.gc.ca>
To: "Nick Catalano" <nick4753@nozone.net>; "PHP list"
<php-general@lists.php.net>
Sent: Thursday, June 29, 2000 4:10 PM
Subject: Re: [PHP] Send HTML email
> Nick Catalano wrote:
>
> > This is basic, since all HTML mail is, is well, a HTML page sent through
a
> > mail server... so you can include forms in it, just like on a normal PHP
> > page... example follows:
> >
> > <?php
> > mail($mail_to, $mail_subject, "
> > ?>
> > <!--
> > Hello?? Your Email program Does NOT Support HTML Email!!!
> > Upgrade for gods sake!!!
> > --->
> > <html>
> > <head>
> > <title> etc... etc... etc... etc... etc...
> >
> > <?php
> > ", "Content-Type: text/html\n From: $mail_from\n");
> > ?>
> > ----- Original Message -----
> > From: "Bernie Huang" <bernie.huang@ec.gc.ca>
> > To: "PHP list" <php-general@lists.php.net>
> > Sent: Thursday, June 29, 2000 4:53 PM
> > Subject: [PHP] Send HTML email
> >
> > > Hi,
> > >
> > > Yet another common question. =)
> > > I am writing a PHP script and am trying to send an HTML email use PHP
> > > function 'mail()'. What I want to do is to include a clickable form
or
> > > an embedded url (haven't decide which one to use, but hope to hear
some
> > > suggestions) in the email, so that the user can click on the button or
> > > url to do some sort of submitting action. How can I do it?
> > >
> > > Thanks.
> > >
> > >
> > > - Bernie
> > >
> > >
> >
>
> --------------------------------------------------------------------------
--
> > ----
> >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-general-help@lists.php.net
> > > To contact the list administrators, e-mail:
php-list-admin@lists.php.net
>
> I guess this didn't work.
>
> Code:
> if ($email)
> {
> $subject = "Whatever";
> $message = "<html><body>This is a test.<form><input
> type=\"reset\"
> value=\"Reset\"></form></body></html>";
> mail($row[email], $subject, $message, 'Content-Type: text/html\n From:
> who@whoever.who');
> }
>
> Email I received:
> <html><body>This is a test.<form><input type="reset"
> value="Reset"></form></body></html>
>
>
> What's happening? I put in the header 'Contect...'?
>
> - Bernie
>
>