#  > Desenvolvimento >  > Linguagens de Programação >  >  Enviar e-mail com Anexo usando php?

## Neckratal

Bom dia para todos.

Tenho que fazer um formulário para enviar e-mail com anexo alguem sabe como fazer isso em php?

Grato

Antonio Henrique (Neckratal) <IMG SRC="images/forum/icons/icon21.gif">

----------


## 1c3m4n

aki tem varios exemplos..... vc vai ter q fazer upload de arquivo:
www.php.net

----------


## Neckratal

Depois de muito sofrimento consegui achar na net como enviar e-mail com anexo no php.

E para v6s nao terem o mesmo sofrimento esta aqui a solução.

<? 

$from = "[email protected]";
$cc = "[email protected]";
$bcc = "[email protected]";

$attach = "arquivo.txt";

$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&quot<IMG SRC="images/forum/icons/icon_wink.gif"> 
{ 
$file = fopen("$attach", "r&quot<IMG SRC="images/forum/icons/icon_wink.gif">; 
$contents = fread ($file, filesize ($attach)); 
$encoded_attach = chunk_split(base64_encode($contents)); 
fclose($file); 

$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); 
?>

----------


## MAJOR

valeww Neckratal , a comunidade agradece!


<IMG SRC="images/forum/icons/icon_biggrin.gif"> <IMG SRC="images/forum/icons/icon_biggrin.gif"> <IMG SRC="images/forum/icons/icon_biggrin.gif"> <IMG SRC="images/forum/icons/icon_wink.gif"> <IMG SRC="images/forum/icons/icon_wink.gif"> <IMG SRC="images/forum/icons/icon_wink.gif"> <IMG SRC="images/forum/icons/icon_smile.gif"> <IMG SRC="images/forum/icons/icon_smile.gif">

----------

