I would do it with the class PHPMailer
, which you can download from here PHPMailer Github
The code I should use would be something similar to this
<?php
require_once("includes/constantes.php");
error_reporting(E_STRICT);
date_default_timezone_set('Europe/Madrid');
require_once('includes/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not
// already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = $SERVIDOR_SMTP; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = $SERVIDOR_SMTP; // sets the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = $correo_Usuario; // SMTP account username
$mail->Password = $correo_Clave; // SMTP account password
$mail->SetFrom( $correo_copia, $correo_NombreCliente);
$mail->AddReplyTo($correo, $correo_NombreCliente);
$mail->AddCC($correo_copia,"");
$mail->AddCC($correo1,"");
if ($achivo !="none") {
$mail->AddAttachment($archivo,$archivo_name);
}
if (isset($dirtemp)){
$mail->AddAttachment($dirtemp,"Parte del Siniestro");
}
//$mail->AddBCC($correo_administrativo, $correo_NombreAdministrativo);
$mail->Subject = strtoupper($asunto);
$mail->MsgHTML($body);
$address = $correo_destino_usado;
//echo "direccion:".$address;
$mail->AddAddress($address);
?>
Where you must define your server variables, emails, passwords and other variables.
The part you care about would be the code
if ($achivo !="none") {
$mail->AddAttachment($archivo,$archivo_name);
}
Where $archivo
will be the path of the attachment and $archivo_name
would be the name of the file that will appear in the email