Jump to content

Como enviar um ficheiro pdf por email atraves do php


Recommended Posts

Boa tarde pessoal,

Estou agora a tentar enviar um ficheiro pdf via web em que o ficheiro está alojado na pasta PDF e o email para enviar ele vai buscar através de variavel.

So que esta me a dar este erro  😉

Warning: fopen(/PDF/testes_1-01-2009.pdf) [function.fopen]: failed to open stream: No such file or directory in

Warning: fread(): supplied argument is not a valid stream resource in

Warning: fclose(): supplied argument is not a valid stream resource in

deixo aqui o código também para ver se descobrem onde esta o erro

$attach = "/PDF/$ficheiro.pdf";

$mailheaders = "From: $from\n";
$mailheaders .= "Reply-To: $from\n";
$mailheaders .= "Cc: $cc\n";
$mailheaders .= "Bcc: $bcc\n";
$mailheaders .= "X-Mailer: Script para enviar arquivo atachado\n";

$msg_body = stripslashes($body);

if ($attach != "none")
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));

$mailheaders .= "MIME-version: 1.0\n";
$mailheaders .= "Content-type: multipart/mixed; ";
$mailheaders .= "boundary=\"Message-Boundary\"\n";
$mailheaders .= "Content-transfer-encoding: 7BIT\n";
$mailheaders .= "X-attachments: $attach_name";

$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";

$msg_body = $body_top . $msg_body;

$msg_body .= "\n\n--Message-Boundary\n";
$msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_body .= "Content-Transfer-Encoding: BASE64\n";
$msg_body .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_body .= "$encoded_attach\n";
$msg_body .= "--Message-Boundary--\n";

mail($to, stripslashes($subject), $msg_body, $mailheaders);

Cumprimentos  🙂

APARTE: Usa o Geshi, torna o código mais apresentável. 🙂


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.