Fw: Consulta sobre correo...
| From: | A/S Gabriel Pirez | Date: | Fri, 20 May 2005 11:10:56 +0000 |
| Subject: | Fw: Consulta sobre correo... | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-54889@lists.php.net to get a copy of this message | ||
Necesito armar una pagina que me envie correos a mis clientes de mi base de datos, esta todo barbaro
pero quiero que las imagenes viajen con el correo y no puedo hacer referencia a mis adjuntos les
mando la clase entera que lee de labase de datos y arma el famoso correo, la idea es que enves de
ver las imagenes en la web quiero que viajen en el correo.
adjunto el codigo que utilizo:
$primeraparte="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Sin titulo</title>
<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">
<style type=\"text/css\">
<!--
.Estilo4 {
font-size: 20px;
color: #00FF00;
font-family: \"Times New Roman MT Extra Bold\", \"Times New Roman\";
}
.Estilo6 { font-size: 12px;
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>
<body>
<table width=\"100%\" border=\"0\" cellpadding=\"4\"
cellspacing=\"0\">
<tr bgcolor=\"#024282\" class=\"HeaderColor\">
<td width=\"7%\" bgcolor=\"#FFFFFF\" style=\"vertical-align:
top\"><img src=\"http://www.alguien.com.uy/noticias/logo.jpg\"></td>
<td width=\"93%\" style=\"vertical-align: top\"><div
align=\"center\"
class=\"Estilo4\">".$encabezado."</div></td>
</tr>
<tr class=\"HeaderColor\">
<td colspan=\"2\" style=\"vertical-align: top\"> <div
align=\"center\"><table width=\"760\" border=\"0\"
align=\"center\">";
//cargando los contenidos
$query= "select * from itemsnews";
$result=mysql_query($query,$conex) or die(mysql_error());
$contenidos="";
while ($myrow=mysql_fetch_array($result))
{
$modelo=$myrow["modelo"];
$imagen=$myrow["imagen"];
$texto=$myrow["texto"];
$texto=str_replace("\n","<br>",$texto);
$texto2=$myrow["texto2"];
$texto2=str_replace("\n","<br>",$texto2);
if ($modelo==1){
$contenidos="<tr>
<td width=\"444\"><div align=\"left\">".$texto."
</div> </td>
<td width=\"210\" nowrap><div align=\"center\"><img
src=\"http://www.alguien.com.uy/noticias/".$imagen."\"></div></td>
</tr>
<tr>
<td colspan=\"2\"><div
align=\"left\">".$texto2." </div></td>
</tr><tr>
<td colspan=\"2\"><hr></td>
</tr>";
}
if ($modelo==2){
$contenidos="<tr>
<td width=\"153\" nowrap><div align=\"center\"><img
src=\"http://www.alguien.com.uy/noticias/".$imagen."\"></div></td>
<td width=\"597\" nowrap><div
align=\"left\">".$texto." </div></td>
</tr>
<tr>
<td colspan=\"2\"><div
align=\"left\">".$texto2."</div></td>
</tr>
<tr>
<td colspan=\"2\"><hr></td>
</tr>";
}
if ($modelo==3){
$contenidos="<tr>
<td nowrap><div
align=\"center\">".$texto."<br>".$texto2."</div></td>
</tr>
<tr>
<td><div align=\"center\"><img src=\"http://www.alguien.com.uy/noticias/".$imagen."\"></div></td>
</tr>
<tr>
<td><hr></td>
</tr>";
}
if ($modelo==4){
$contenidos="<tr>
<td nowrap><div
align=\"center\">".$texto."<br>".$texto2."</div></td>
</tr>
<td><hr></td>
</tr>";
}
}
$segundaparte="</table></div></td>
</tr>
<tr bgcolor=\"#024282\" style=\"vertical-align: top\">
<td colspan=\"2\" class=\"TitleColor\"><table
width=\"100%\" border=\"0\">
<tr>
<td width=\"27%\" valign=\"bottom\"><span
class=\"Estilo6\"></span></td>
<td width=\"73%\" class=\"Estilo6\"><div
align=\"center\">
<p>".$piedepagina."</p>
</div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>";
$HTML=$primeraparte.$contenidos.$segundaparte;
$ATTM=array("logoturisportoriginal.jpg");
SendMail("alguien@alguien.com.uy","blabla", //sender
"alguien@alguien.com.uy","daniel", //recipient
"Testmail", //subject
$TEXT,$HTML,$ATTM); //body and attachment(s)
function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles){
$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."> \r \n";
$headers.="To: ".$ToName." <".$To."> \r \n";
$headers.="Reply-To: ".$FromName." <".$From."> \r \n";
$headers.="X-Priority: 1 \r \n";
$headers.="X-MSMail-Priority: High \r \n";
$headers.="X-Mailer: My PHP Mailer \r \n";
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\" \r
\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\tboundary=\"".$IB."\"\n\n";
//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$Msg.=$Text."\n\n";
// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$Msg.=chunk_split(base64_encode($Html))."\n\n";
// end of IB
$Msg.="\n--".$IB."--\n";
// attachments
if($AttmFiles){
foreach($AttmFiles as $AttmFile){
$patharray = explode ("/", $AttmFile);
$FileName=$patharray[count($patharray)-1];
$Msg.= "\n--".$OB."\n";
$Msg.="Content-Type:
application/octetstream;\n\tname=\"".$FileName."\"\n";
$Msg.="Content-Transfer-Encoding: base64\n";
$Msg.="Content-Disposition:
attachment;\n\tfilename=\"".$FileName."\"\n\n";
//file goes here
$fd=fopen ($AttmFile, "r");
$FileContent=fread($fd,filesize($AttmFile));
fclose ($fd);
$FileContent=chunk_split(base64_encode($FileContent));
$Msg.=$FileContent;
$variable=$FileContent;
$Msg.="\n\n";
}
}
//message ends
$Msg.="\n--".$OB."--\n";
mail($To,$Subject,$Msg,$headers);
echo "Correo enviado con exito.";
}
?>
A/S Gabriel Pirez
gabrielpirez@datagroup.com.uy
Montevideo - Uruguay