You are here: sending an email using mail() and avoiding it to be marked as spam... « PHP Programming Language « IT news, forums, messages
sending an email using mail() and avoiding it to be marked as spam...

Posted by windandwaves on 11/05/06 05:18

Hi Folk

I send an email to confirm when people sign up for a newsletter.
Unfortunately, the emails seem to go straight for the spam boxes.

Does anyone know of a nice email function that allows for HTML+
text-only emails (both in the same email) to be sent without it being
marked as spam?

This is what I use at the moment:

function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html){
$OB="----=_OuterBoundary_000";
$IB="----=_InnerBoundery_001";
$Html=$Html?$Html:preg_replace("/\n/","<BR>",$Text) or die("neither
text nor html part present.");
$Text=$Text?$Text:"Sorry, but you need an html mailer to read this
mail.";
$From or die("sender address missing");
$To or die("recipient address missing");
$headers ="MIME-Version: 1.0\r\n";
$headers.="From: ".$FromName." <".$From.">\n";
$headers.="To: ".$ToName." <".$To.">\n";
$headers.="Reply-To: ".$FromName." <".$From.">\n";
$headers.="X-Mailer: My PHP Mailer\n";
$headers.="Content-Type: multipart/mixed;\n boundary=\"".$OB."\"\n";
//Messages start with text/html alternatives in OB
$Msg ="This is a multi-part message in MIME format.\n";
$Msg.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n
boundary=\"".$IB."\"\n\n";
//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n charset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
$Msg.=$Text."\n\n";
// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n charset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
$Html =str_replace('\\','',$Html);
$Msg.=chunk_split(base64_encode($Html))."\n\n";
// end of IB
$Msg.="\n--".$IB."--\n";
//message ends
$Msg.="\n--".$OB."--\n";
if(!$subject or $subject = "") {
$subject = "no subject";
}
mail($To,$Subject,$Msg,$headers);
syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");
return 1;
}


Thank you

> Nicolaas

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация