1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//$expediteur = $_SESSION['mail'];
//join un fichier pdf au mail
//permet d'envoyer le mail à un utilisateur ou plusieurs => $destinataire est un tableau de 1 ou n utilisateurs
//function appelé dans :
//- pdfgen_ok_peinture.php
function mail_validation_peinture($num_bon,$nom_bon,$expediteur,$destinataire,$nom_piece_jointe,$message)
{
$num_destinataire=count($destinataire);
$nom_expediteur="Alerte_validation_peinture";
for ($i=0;$i<$num_destinataire;$i++)
{
$uploaddir = './_state/';
$upload_file = $uploaddir .$nom_piece_jointe;
$attach_type = "application/pdf";
$attach_name = $nom_piece_jointe;
$destinataires = $destinataire[$i];
$objet="Validation de la peinture : bon peinture N°$nom_bon";
//$message="Le bon peinture n°$num_bon est validé par la peinture. <br />
//Veuillez imprimer la pièce jointe.<br />";
if (file_exists($upload_file))
{
$file = fopen($upload_file, "r");
$contents = fread($file, filesize($upload_file));
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);
}
$mailheaders = "From: $nom_expediteur\n";
$mailheaders .= "Importance:1\n";
$mailheaders .= "Reply-To: $expediteur\n";
//$mailheaders .= "To: $destinataires\n";
$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\n";
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/html;charset=ISO-8859-1\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$msg_body = $body_top.$message;
$msg_body .= "\n\n--Message-Boundary\n";
$msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_body .= "Content-Length: " . filesize($upload_file) . "\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($destinataires,$objet,$msg_body,$mailheaders);
}
} |
Partager