Problème envoi de mail en php pièce jointe PDF

tipherchos Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -  
 Profil bloqué -
Bonjour,

Je dois créer une fonction en PHP qui envoie un mail avec un message en HTML et une pièce jointe en PDF. Je pense avoir écrit le bon code mais le mail ne s'envoie pas. Avez vous des solutions ou des conseils ?

$mail=$tab[0]; //Le mail est normalement la première ligne du tableau
 
 
 //Après avoir récupéré l'adresse mail, on envoie le mail avec une pièce jointe
 $sujet = 'Objet du mail';   
  
 $message = '<div style="    width: 70%; margin: 75px; padding: 10px; box-shadow: 1px 1px 12px black; display: inline-block;">
     <h1 style="font-family: Sans-Serif;  font-size: 15px;"><img src="logo.jpg"/><br />Bonjour</h1>
     </br>
     <p  style="font-family: Sans-Serif; font-size: 12px;"> Votre inscription a bien été prise en compte, Veuillez trouver ci-joint votre invitation que vous devrez présenter à la journée d\'accueil</p></div>';
  
 $separator = md5(time()); //chaine aléatoire pour envoyer le mixed content
  
 $eol = "\r\n"; //retour charriot
 $filename="inscription.pdf";
 
 $destinataire = $mail;
 
 $fichier = fopen("inscription.pdf", "r");
 $attachment = fread($fichier, filesize("inscription.pdf"));
 $attachment = chunk_split(base64_encode($attachment));
 fclose($fichier);
 
 $headers = "From: \"Moi\"<noreply@moi.fr>".$eol;
 $headers .= "Reply-To: moi@domaine.com".$eol;
 $headers .= "MIME-Version: 1.0".$eol;
 $headers .= "Content-Type: multipart/mixed;{$eol}\tboundary=\"".$separator."\"";
  
 $body = "--".$separator.$eol;
 $body .= "Content-Type: text/html; charset=\"utf-8\"".$eol;
 $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
 $body .= $message;
 $body .= $eol.$eol;
  
 $body .="--".$separator.$eol;
 $body .="Content-Type: application/pdf; name=\"".$filename."\"".$eol;
 $body .="Content-Transder-Encoding: base64".$eol;
 $body .="Content-Disposition: attachment; filename=\"inscription.pdf\"".$eol.$eol;
 $body .= $attachment.$eol;
 $body .= "--".$separator.$eol;
 
 if(mail($destinataire,$sujet,$body,$headers))
 {
 echo "Un email de confirmation contenant l'invitation à présenter le jour J à été envoyé à $mail";
 }
 else
 {
 echo "Une erreur s'est produite lors de l'envoi de l'email.";
 }
A voir également:

1 réponse

Profil bloqué
 
Ou se trouve ta fonction mail même que tu as appelé?
0