Fabio Sampaio
Fabio Sampaio

Reputation: 153

Multiple file attachments with mail()

I'm trying to attach TWO files to an email, but I don't know why I'm getting a lot of problems. I need just more one file attached. What to do?

Here the code:

$arquivo = isset($_FILES["fileCURR"]) ? $_FILES["fileCURR"] : FALSE;

$fp = fopen($_FILES["fileCURR"]["tmp_name"],"rb"); 
$anexo = fread($fp,filesize($_FILES["fileCURR"]["tmp_name"])); 
$anexo = base64_encode($anexo); 

fclose($fp); 

$anexo = chunk_split($anexo); 

$boundary = "XYZ-" . date("dmYis") . "-ZYX"; 

$mens = "--$boundary" . $quebra_linha . ""; 
$mens .= "Content-Transfer-Encoding: 8bits" . $quebra_linha . ""; 
$mens .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $quebra_linha . "" . $quebra_linha . ""; //plain 
$mens .= "<strong>E-mail:</strong> $emailt <br> <strong>Website:</strong> $website" . $quebra_linha . ""; 
$mens .= "--$boundary" . $quebra_linha . ""; 
$mens .= "Content-Type: ".$arquivo["type"]."" . $quebra_linha . ""; 
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"" . $quebra_linha . ""; 
$mens .= "Content-Transfer-Encoding: base64" . $quebra_linha . "" . $quebra_linha . ""; 
$mens .= "$anexo" . $quebra_linha . ""; 
$mens .= "--$boundary--" . $quebra_linha . ""; 

$headers = "MIME-Version: 1.0" . $quebra_linha . ""; 
$headers .= "From: $email_from " . $quebra_linha . ""; 
$headers .= "Return-Path: $email_from " . $quebra_linha . ""; 
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"" . $quebra_linha . ""; 
$headers .= "$boundary" . $quebra_linha . ""; 

mail($email,$assunto,$mens,$headers, "-r".$email_from); 

echo"Success!";

Upvotes: 0

Views: 83

Answers (1)

brunoroc
brunoroc

Reputation: 21

To be honest, it would be way more simple and easy if you just add the file links to the email body, since you have uploaded the files in a form and stored then in you server, you can just link then in the email body.

Upvotes: 1

Related Questions