I have this problem in my web page, I need to send a file via email to someone, the problem that I have is that the mail arrives without an attachment and a lot of strange characters, I leave you my code:
$boundary='Datos Adjuntos';
$boundary.=" ".md5(time());
//Cabeceras del email
$headers ="From: Example <name@example.com>\r\n";
$headers .= "Reply-To: <name@example.com>\r\n";
// $headers .="MIME-Version: 1.0\r\n";
$headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n\n";
$body="--". $boundary ."\n";
$body .= "Content-Type: text/html; charset=ISO-8859-1\r\n\n";
$archivo=file_get_contents($dir."/".$handle->file_dst_name);
$archivo=chunk_split(base64_encode($archivo));
//Escritura del archivo adjunto
$body .= $body .$ContenidoString. "--" .$boundary. "\n";
//Content-Type: application/msword; name=\"nombre_archivo\"\r\n
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: attachment; filename=\"".$handle->file_dst_name."\"\r\n\n$archivo";
$body = $body . "--" . $boundary ."--";
Correo::Enviar("OPERACION","name@example.com", $body,$headers);
The $ContentString
is the html of the email, I use the upload class to upload the file to the server and then send it, I leave you a piece of the email that I receive:
This is after all the other things lik e## e name and ## e content of the email.
--Datos Adjuntos 1c436ca78c5925e7096267f0eae3a7d3 Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="9cbdf187_3251_42e5_aeaa_84df343a227d_4.pdf" JVBERi0xLjQKJdP0zOEKMSAwIG9iago8PAovQ3JlYXRpb25EYXRlKEQ6MjAxMTA4MTYxNTEyNDIt MDUnMDAnKQovQ3JlYXRvcihQREZzaGFycCAxLjMuMTY4NC1nIFwod3d3LnBk
text/html
portion of the message... – DaveRandom