skov | Bonjour,
J'envoie mon e-mail depuis un site hébergé sur one and one, sur le messagerie one and one tout se passe bien, j'ai tester sur hotmail çà passe aussi. par contre sur gmail, il semble ne pas prendre mon header.
J'ai fait le tour de nombreux forum pour voir les solutions existantes mais je dois avoir les yeux qui ne voit plus clairs car je vois pas d'où vient le problème.
Voici mon code et le résultat dans gmail
Code :
- <?php
- session_start();
- require('fct_espclient.php');//insertion page fonctions
- $session_id=$_SESSION['session_id'];
- if (!isset($_SESSION['session_id']))
- {
- echo "<script language='javascript'>window.top.location.href='index.php'</script>";
- }
- else
- {
- $f=connect();
- $action_id=$_POST["action_id"];
- $struct_id=$_POST["struct_id"];
- if (isset($_POST["urgent"]))$urgent="urgent: ";
- else $urgent="";
- $struct_mail=$_POST["struct_mail"];
- $objet=$_POST["objet"];
- $contenu=$_POST["contenu"];
- $struct_nom=$_POST["struct_nom"];
- include('menugen.php');
- echo "<table width='70%' border='0' cellspacing='0' cellpadding='0'>";
- if (isset($_FILES['userfile']) && is_uploaded_file($_FILES['userfile']['tmp_name'])or ((isset($_POST['doc_id']))and($_POST['doc_id']!="" ))) $HA_supp="oui";
- else $HA_supp="non";
- $requete1=mysql_query("select * from utilisateur,session where (session.session_id=$session_id)and(session.user_id=utilisateur.user_id)" );
- while ($row=mysql_fetch_array($requete1))
- {
- $d=date("Y-m-d" );
- $query = "INSERT INTO heure_action (HA_id,tache_id,HA_date,HA_comment,user_id,HA_supp,comm_id,HA_etat,action_id)
- VALUES('','2','$d',\"mail à $struct_nom \",'$row[user_id]','$HA_supp','1','valide','$action_id');";
- $result = MYSQL_QUERY($query);
- $req_sess="select max(HA_id) k from heure_action";
- $result_sess = MYSQL_QUERY($req_sess);
- while($rsk = mysql_fetch_object($result_sess))
- {
- $HA_id=$rsk->k;
- }
- mysql_free_result($result_sess);
- mysql_query("insert into message values ('',\"$objet\",\"$contenu\",'$HA_id','non')" );
- $req_sess="select max(mess_id) k from message";
- $result_sess = MYSQL_QUERY($req_sess);
- while($rsk = mysql_fetch_object($result_sess))
- {
- $mess_id=$rsk->k;
- }
- mysql_free_result($result_sess);
- mysql_query("insert into mess_struc values ('','$mess_id','$struct_id')" );
- $suj=$urgent.$objet;
- $mail_to ="xxxxxxxxxx@hotmail.com";//Destinataire
- $from_mail = $row['user_mail']; //Expediteur
- $from_name = $row['user_mail']; //Votre nom, ou nom du site
- $reply_to = $row['user_mail']; //Adresse de réponse
- $subject = utf8_decode($suj);
- $subject = mb_encode_mimeheader($subject,"UTF-8" );
- $contenuhtml="";
- echo "<tr>
- <td align='left'><font face='Verdana' size='2'>From: $from_mail</font></td>
- </tr>
- <tr>
- <td align='left'><font face='Verdana' size='2'>To: $mail_to</font></td>
- </tr>
- <tr>
- <td align='left'><font face='Verdana' size='2'>$subject</font></td>
- </tr>
- <tr>
- <td align='left'><font face='Verdana' size='2'>";
- $matches=preg_split("/\n/i","$contenu" );
- $i=0;
- while (isset($matches[$i]))
- {
- if ($i!=0) echo "<br>";
- echo "$matches[$i]";
- $contenuhtml.=$matches[$i]."<br>";
- $i++;
- }
- echo "</font></td>
- </tr>";
- // clé aléatoire de limite
- srand((double)microtime()*1000000);
- $boundary = md5(uniqid(rand()));
- // Headers
- $entete = "MIME-Version: 1.0 \n";
- $entete .= "Content-Type: multipart/mixed; boundary=\"$boundary\" \n";
- $entete .= "From: $from_mail \n";
- $entete .= "Bcc: $from_mail, blain1965@gmail.com \n";
- $entete .= "X-Priority: 1 \n";
- $entete .= "Content-Transfer-Encoding:8bit \n";
- $entete .= 'X-Mailer: PHP/' . phpversion();
- $entete .= " \n";
- // Message
- $message = "This is a multi-part message in MIME format. \n";
- $message .= "--$boundary \n";
- $message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n";
- $message .= "Content-Transfer-Encoding: binary\n";
- $message .= $contenu;
- $message .= "\n";
- $message .= "--$boundary \n";
- $message .= "Content-Type: text/html; charset=\"iso-8859-1\" \n";
- $message .= "Content-Transfer-Encoding:binary \n";
- $message .= "\n";
- $message .= $contenuhtml;
- $message .= "\n";
- // Pièce jointe
- if (isset($_POST['doc_id']))
- {
- $requete2=mysql_query("select doc_nom from document where(doc_id=$_POST[doc_id])" );
- while ($res=mysql_fetch_array($requete2))
- {
- $file_name = $res['doc_nom'];
- if (file_exists(".docs/".$file_name))
- {
- $file_type = filetype(".docs/".$file_name);
- $file_size = filesize(".docs/".$file_name);
- $content = file_get_contents(".docs/".$file_name);
- $content = chunk_split(base64_encode($content));
- $message .= "--$boundary \n";
- $message .= "Content-type: $file_type;name=\"$file_name\"\n";
- $message .= "Content-transfer-encoding:base64 \n";
- $message .= "Content-Disposition: attachment; filename=\"$file_name\" \n";
- $message .= "\n";
- $message .= $content."\n";
- $message .= "\n";
- mysql_query("insert into mess_pj values ('','$mess_id','$_POST[doc_id]','')" );
- }
- }
- mysql_free_result($requete2);
- }
- if (isset($_FILES['userfile']) && is_uploaded_file($_FILES['userfile']['tmp_name']))
- {
- $file_name = $_FILES['userfile']['name'];
- $file_type = filetype($_FILES['userfile']['tmp_name']);
- $file_size = filesize($_FILES['userfile']['tmp_name']);
- $content = chunk_split(base64_encode(file_get_contents($_FILES['userfile']['tmp_name'])));
- $message .= "--$boundary \n";
- $message .= "Content-type: $file_type;name=\"$file_name\"\n";
- $message .= "Content-transfer-encoding:base64 \n";
- $message .= "Content-Disposition: attachment; filename=\"$file_name\" \n";
- $message .= "\n";
- $message .= $content."\n";
- $message .= "\n";
- mysql_query("insert into mess_pj values ('','$mess_id','',\"$file_name\" )" );
- unlink($_FILES['userfile']['tmp_name']);
- //...
- }
- // Fin
- $message .= "--".$boundary."-- \n end of the multi-part";
- // Function mail()
- mail($mail_to, $subject, $message, $entete);
- }
- mysql_free_result($requete1);
- mysql_close($f);
- ?>
- <tr><td align='center'><br><img src='image/fermerp.jpg' onClick="window.close()" alt='Fermer'></td></tr>
- </table>
- </div>
- </body>
- </html>
- <?php
- }
- ?>
|
J'ai deux sources possible pour les pièces jointes, soit sur l'herbergeur (listées sur une BDD) soit uploader
Code :
- From: xxxxxx@gmail.com
- To:
- Date: Sun, 22 Dec 2013 22:24:04 +0100
- Subject: test
- This is a multi-part message in MIME format.
- --56cb8620624e6641bbe66343a30b06c0
- Content-Type: text/plain; charset="ISO-8859-1"
- Content-Transfer-Encoding: binary
- teste
- --56cb8620624e6641bbe66343a30b06c0
- Content-Type: text/html; charset="iso-8859-1"
- Content-Transfer-Encoding:binary
- teste<br>
- --56cb8620624e6641bbe66343a30b06c0
- Content-type: file;name="Affiche fete noel 2013.pdf"
- Content-transfer-encoding:base64
- Content-Disposition: attachment; filename="Affiche fete noel 2013.pdf"
- JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFu
- Zyhmci1GUikgL1N0cnVjdFRyZWVSb290IDgwIDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4v
- UGFnZUxhYmVscyAxMTAgMCBSPj4NCmVuZG9iag0KMiAwIG9iag0KPDwvVHlwZS9QYWdlcy9Db3Vu
- dCAxL0tpZHNbIDMgMCBSXSA+Pg0KZW5kb2JqDQozIDAgb2JqDQo8PC9UeXBlL1BhZ2UvUGFyZW50
- IDIgMCBSL1Jlc291cmNlczw8L1hPYmplY3Q8PC9JbWFnZTUgNSAwIFIvSW1hZ2U3IDcgMCBSL0lt
- <<je raccourci ici>>
- bGVyDQo8PC9TaXplIDExMi9Sb290IDEgMCBSL0luZm8gNzkgMCBSL0lEWzw0Q0JDMUJDREM1NzU3
- OTQ0QUY5MERCMEY4OTMwMkU0MD48NENCQzFCQ0RDNTc1Nzk0NEFGOTBEQjBGODkzMDJFNDA+XSAv
- UHJldiA3NjczMTMvWFJlZlN0bSA3NjY3NjE+Pg0Kc3RhcnR4cmVmDQo3Njk3MTMNCiUlRU9G
- --56cb8620624e6641bbe66343a30b06c0--
- end of the multi-part
|
merci d'avance |