sending html email using php script

This is a discussion on sending html email using php script within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am trying to send a html email from a php script. This script emails a common information to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-04-2004
Ann
 
Posts: n/a
Default sending html email using php script

Hi,

I am trying to send a html email from a php script. This script emails
a common information to all the members in the database. The only
problem is I cannot specify colors, hyperlinks etc..Html tags like
<h1></h1>, <br/>, <b> etc works though..

Could any one tell me what i might be doing wrong? Any help will be
greatly appreciated.

Thanks,
Ann

Code:
function mail_it($content, $subject, $email, $recipient) {
global $attachment_chunk, $attachment_name, $attachment_type,
$attachment_sent, $bcc;
global $db;
global $msgbody;

$ob = "----=_OuterBoundary_000";
$ib = "----=_InnerBoundery_001";

$sql_result = mysql_query("SELECT * FROM contacts", $db);
echo "<br/><b>Emails sent to:</b><br/>";

while($rs = mysql_fetch_array($sql_result))
{
$message = "";
$headers = "";
$recip = $rs["Email"];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$email."\r\n";
$headers .= "To: ".$recip."\r\n";
$headers .= "Reply-To: ".$email."\r\n";
if ($bcc) $headers .= "Bcc: ".$bcc."\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-Mailer: Formmail".VERSION."\r\n";
$headers .= "Content-Type:
multipart/mixed;\r\n\tboundary=\"".$ob."\"\r\n";

$ToName = $rs["Salutation"]."".$rs["FirstName"]."
".$rs["LastName"];


$content = "Hello ".$ToName.",<br/><br/>";
$content .= $msgbody;
$content .=" <br/><br/>";
$content .="Thank you.";
$content .=" <br/><br/><br/>";
$content .="<small><font color='blue'>Please send an email to <a
href='mailto:abc@def.com&subject='Re:Email Notifications' to get more
information.</font></small>";


$message .= "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n--".$ob."\r\n";
$message .= "Content-Type:
multipart/alternative;\r\n\tboundary=\"".$ib."\"\r\n\r\n";
$message .= "\r\n--".$ib."\r\n";
//$message .= "Content-Type:
text/plain;\r\n\tcharset=\"iso-8859-1\"\r\n";
$message .= "Content-Type:
text/html;\r\n\tcharset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding:
quoted-printable\r\n\r\n";
$message .= $content."\r\n\r\n";
$message .= "\r\n--".$ib."--\r\n";
if ($attachment_name && !$attachment_sent) {
$message .= "\r\n--".$ob."\r\n";
$message .= "Content-Type:
$attachment_type;\r\n\tname=\"".$attachment_name." \"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition:
attachment;\r\n\tfilename=\"".$attachment_name."\" \r\n\r\n";
$message .= $attachment_chunk;
$message .= "\r\n\r\n";
$attachment_sent = 1;
}
$message .= "\r\n--".$ob."--\r\n";

mail($recip, $subject, $message, $headers);
}

}
Reply With Quote
  #2 (permalink)  
Old 10-05-2004
Marco Dieckhoff
 
Posts: n/a
Default Re: sending html email using php script

On 2004-10-04, Ann <nsajus@yahoo.com> wrote:
> Hi,
>
> I am trying to send a html email from a php script. This script emails
> a common information to all the members in the database. The only
> problem is I cannot specify colors, hyperlinks etc..Html tags like
><h1></h1>, <br/>, <b> etc works though..
>
> Could any one tell me what i might be doing wrong? Any help will be
> greatly appreciated.


No one likes HTML mails.
Your php knows that.

SCNR :)

Mail is Mail, not Web.

If you want your users to view Webpages send them a link.

And: HTML mails are often placed higher in spam rankings,
especially when not send correctly. So there's a high chance your
receivers will never read that, because their spam filters catch
it.

--
Marco Dieckhoff
icq# 22243433
GPG Key 0x1A6C95BA -- http://www.frankonia-brunonia.de/keys
Reply With Quote
  #3 (permalink)  
Old 10-05-2004
nipepsi
 
Posts: n/a
Default Re: sending html email using php script

Ann a écrit :
> Hi,
>
> I am trying to send a html email from a php script. This script emails
> a common information to all the members in the database. The only
> problem is I cannot specify colors, hyperlinks etc..Html tags like
> <h1></h1>, <br/>, <b> etc works though..
>
> Could any one tell me what i might be doing wrong? Any help will be
> greatly appreciated.
>
> Thanks,
> Ann
>
> Code:
> function mail_it($content, $subject, $email, $recipient) {
> global $attachment_chunk, $attachment_name, $attachment_type,
> $attachment_sent, $bcc;
> global $db;
> global $msgbody;
>
> $ob = "----=_OuterBoundary_000";
> $ib = "----=_InnerBoundery_001";
>
> $sql_result = mysql_query("SELECT * FROM contacts", $db);
> echo "<br/><b>Emails sent to:</b><br/>";
>
> while($rs = mysql_fetch_array($sql_result))
> {
> $message = "";
> $headers = "";
> $recip = $rs["Email"];
> $headers = "MIME-Version: 1.0\r\n";
> $headers .= "From: ".$email."\r\n";
> $headers .= "To: ".$recip."\r\n";
> $headers .= "Reply-To: ".$email."\r\n";
> if ($bcc) $headers .= "Bcc: ".$bcc."\r\n";
> $headers .= "X-Priority: 1\r\n";
> $headers .= "X-Mailer: Formmail".VERSION."\r\n";
> $headers .= "Content-Type:
> multipart/mixed;\r\n\tboundary=\"".$ob."\"\r\n";
>
> $ToName = $rs["Salutation"]."".$rs["FirstName"]."
> ".$rs["LastName"];
>
>
> $content = "Hello ".$ToName.",<br/><br/>";
> $content .= $msgbody;
> $content .=" <br/><br/>";
> $content .="Thank you.";
> $content .=" <br/><br/><br/>";
> $content .="<small><font color='blue'>Please send an email to <a
> href='mailto:abc@def.com&subject='Re:Email Notifications' to get more
> information.</font></small>";
>
>
> $message .= "This is a multi-part message in MIME format.\r\n";
> $message .= "\r\n--".$ob."\r\n";
> $message .= "Content-Type:
> multipart/alternative;\r\n\tboundary=\"".$ib."\"\r\n\r\n";
> $message .= "\r\n--".$ib."\r\n";
> //$message .= "Content-Type:
> text/plain;\r\n\tcharset=\"iso-8859-1\"\r\n";
> $message .= "Content-Type:
> text/html;\r\n\tcharset=\"iso-8859-1\"\r\n";
> $message .= "Content-Transfer-Encoding:
> quoted-printable\r\n\r\n";
> $message .= $content."\r\n\r\n";
> $message .= "\r\n--".$ib."--\r\n";
> if ($attachment_name && !$attachment_sent) {
> $message .= "\r\n--".$ob."\r\n";
> $message .= "Content-Type:
> $attachment_type;\r\n\tname=\"".$attachment_name." \"\r\n";
> $message .= "Content-Transfer-Encoding: base64\r\n";
> $message .= "Content-Disposition:
> attachment;\r\n\tfilename=\"".$attachment_name."\" \r\n\r\n";
> $message .= $attachment_chunk;
> $message .= "\r\n\r\n";
> $attachment_sent = 1;
> }
> $message .= "\r\n--".$ob."--\r\n";
>
> mail($recip, $subject, $message, $headers);
> }
>
> }

Use php.classmailer ; it 's a nice class
Reply With Quote
  #4 (permalink)  
Old 10-05-2004
 
Posts: n/a
Default Re: sending html email using php script

> No one likes HTML mails.
> Your php knows that.
>
> SCNR :)
>
> Mail is Mail, not Web.
>
> If you want your users to view Webpages send them a link.
>
> And: HTML mails are often placed higher in spam rankings,
> especially when not send correctly. So there's a high chance your
> receivers will never read that, because their spam filters catch
> it.


Wrong day of the week for a Sermon buddy --

--Wil


Reply With Quote
  #5 (permalink)  
Old 10-06-2004
Shawn Wilson
 
Posts: n/a
Default Re: sending html email using php script

laidbak69@hotmail.com wrote:
>
> > No one likes HTML mails.
> > Your php knows that.
> >
> > Mail is Mail, not Web.
> >
> > If you want your users to view Webpages send them a link.
> >
> > And: HTML mails are often placed higher in spam rankings,
> > especially when not send correctly. So there's a high chance your
> > receivers will never read that, because their spam filters catch
> > it.

>
> Wrong day of the week for a Sermon buddy --


<obligatory>
- I agree with that guy about HTML emails, but understand that sometimes you
don't have a choice
- Single quotes are usually preferable for PHP strings, as PHP doesn't have to
search them for variables
- Though most browsers parse them okay, you really should use double quotes for
HTML attributes
- *cough*CSS*cough*
</obligatory>

$content .="<small><font color='blue'>Please send an email to <a
href='mailto:abc@def.com&subject='Re:Email Notifications' to get more
information.</font></small>";

^^^^ this line is suspicious. Unless my NG reader mangled the mailto (which is
entirely possible), you don't have a closing </A> tag, you have a '&' instead of
'?' for the query string, you have a space and a single quote in your subject,
you didn't close your opening A tag with a '>' or even the proper quote


I'd try this:
$content .='<small><font color="blue">Please send an email to <a
href="mailto:abc@def.com?subject='.urlencode('Re:E mail Notifications').'">some
address</a> to get more information.</font></small>';

If that doesn't fix it, try viewing source and copying the HTML from the emails
you receive and run it through the w3c html validator (somewhere at w3c.org).

Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB 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 07:48 AM.


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