Mensagem sobre o tópico
Ajuda!! Envio de email com anexo
MIME-Version: 1.0
Message-ID: <90b7a277-96ad-4eaf-90c9-e282fb4ef682@59g2000hsb.googlegroups.com>
Date: Thu, 15 May 2008 10:16:25 -0700 (PDT)
Received: by 10.100.173.18 with SMTP id v18mr26601ane.0.1210871785970; Thu, 15
May 2008 10:16:25 -0700 (PDT)
X-IP: 201.17.146.84
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
InfoPath.2),gzip(gfe),gzip(gfe)
Subject: Ajuda!! Envio de email com anexo
From: Vitor de Oliveira <vito...@gmail.com>
To: LISTA PHP <listaphp@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Esse meu codigo de envio de email com anexo esta funcionando mas o
anexo nao aparece com a extens=E3o correta aparece . dat e o correto
seria .pdf
Segue abaixo o codigo
<?php $from =3D "cont...@webforte.com.br";
$to =3D "vitor.carva...@hcscomp.com.br";
$body =3D "Corpo do email";
$subject =3D "Assunto do email";
$mailheaders =3D "From: $from\n";
$mailheaders .=3D "X-Mailer: Script para enviar arquivo atachado\n";
$msg_body =3D stripslashes($body);
$attach =3D "xml_xsl.pdf";
$attach_size =3D filesize($attach);
$attach_name =3D "xml_xsl";
$attach_type =3D filetype($attach);
$file =3D fopen($attach, "r");
$contents =3D fread($file, $attach_size);
$encoded_attach =3D chunk_split(base64_encode($contents));
fclose($file);
$mailheaders .=3D "MIME-version: 1.0\n";
$mailheaders .=3D "Content-type: multipart/mixed; ";
$mailheaders .=3D "boundary=3D\"Message-Boundary\"\n";
$mailheaders .=3D "Content-transfer-encoding: 7BIT\n";
$mailheaders .=3D "X-attachments: $attach_name";
$body_top =3D "--Message-Boundary\n";
$body_top .=3D "Content-type: text/plain; charset=3DUS-ASCII\n";
$body_top .=3D "Content-transfer-encoding: 7BIT\n";
$body_top .=3D "Content-description: Mail message body\n\n";
$msg_body =3D $body_top . $msg_body;
$msg_body .=3D "\n\n--Message-Boundary\n";
$msg_body .=3D "Content-type: $attach_type; name=3D\"$attach_name
\"\n";
$msg_body .=3D "Content-Transfer-Encoding: BASE64\n";
$msg_body .=3D "Content-disposition: attachment; filename=3D
\"$attach_name\"\n\n";
$msg_body .=3D "$encoded_attach\n";
$msg_body .=3D "--Message-Boundary--\n";
$mensagem =3D mail($to, stripslashes($subject), $msg_body,
$mailheaders);
if ($mensagem) {
print "E-mail enviado com sucesso!";
} else {
print "O envio do email falhou!";
}