Bonjour,
Ayant la contrainte de ne pas pouvoir exploiter la fonction mail de PHP, je passe par la classe de PHP MAILER pour envoyer des mails.
Tout fonctionne sauf que quand je veux joindre plusieurs fichiers, ils s'enregistrent bien dans le dossier mais seulement le premier arrive correctement par mail. Pourriez-vous m'aider?
Merci d'avance.
CODE PHP:
CODE HTML:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 if(isset($_POST['send_mail'])){ $error = ''; $mail = new PHPmailer(); $mail->IsSMTP(); $mail->IsHTML(true); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Port = TXT_PORT; $mail->Username = TXT_EMAIL_ADDRESS; $mail->Password = TXT_PASSWORD; $mail->From = TXT_EMAIL_ADDRESS;//mon adresse mail $mail->FromName = 'Ads Cambodia'; $mail->AddAddress($_POST['email_address']);//Destinataire $mail->AddReplyTo(TXT_EMAIL_ADDRESS);//mon adresse mail $mail->CharSet = 'utf-8'; $mail->ConfirmReadingTo = TXT_EMAIL_ADDRESS; foreach($_FILES as $file){ $directory = "./upload_mail/"; $target_path = $directory .basename($file['name']); if(move_uploaded_file($file['tmp_name'], $target_path)){ echo "the file ".basename($file['name'])." has been uploaded"; }else{ echo "there was an error"; } $mail->AddAttachment($target_path); } $mail->Subject = $_POST['subject']; $mail->Body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $mail->Body .= '<html xmlns="http://www.w3.org/1999/xhtml">'; $mail->Body .= '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Document sans nom</title></head>'; $mail->Body .= '<body>'; $mail->Body .= $_POST['message']; $mail->Body .= '<p><hr />H/P : +855 (0) 97 981 02 74<br />Website : www.ads-cambodia.com<br />Please consider the environment before printing this e-mail</p>'; $mail->Body .= '</body></html>'; if(!$mail->Send()){ //Teste si le return code est ok. echo $mail->ErrorInfo; //Affiche le message d'erreur (ATTENTION:voir section 7) } else{ echo 'Mail Sent !'; } $mail->SmtpClose(); unset($mail); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61 <script> function create_champ(i) { var i2 = i + 1; document.getElementById('leschamps_'+i).innerHTML = '<input type="file" name="file'+i+'"></span>'; document.getElementById('leschamps_'+i).innerHTML += (i <= 5) ? '<br /><span id="leschamps_'+i2+'"><a href="javascript:create_champ('+i2+')">Add attachments</a></span>' : ''; } </script> <form name="send_mail" action="?section=sendmail" enctype="multipart/form-data" method="post"> <table width="500" border="0"> <tr> <td colspan="2"><h1>Send an email at : <?php echo $row_mail['u_first_name']." ".$row_mail['u_last_name'];?></h1></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Subject :</td> <td> <input type="hidden" name="email_address" value="<?php echo $row_mail['u_email'];?>" /> <input style="width:220px" type="text" name="subject" /> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td valign="top">Message :</td> <td><textarea name="message" cols="45" rows="20">Dear <?php echo $row_mail['u_first_name']." ".$row_mail['u_last_name'];?>,</textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Attachment :</td> <td><input type="file" name="file" /></td> </tr> <tr> <td> </td> <td><input type="hidden" name="max_file_size" value="<?php echo $max_file_size;?>" /></td> </tr> <tr> <td> </td> <td><span id="leschamps_4"><a href="javascript:create_champ(4)">Add attachments</a></span><br /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="send_mail" value="Send" /></td> </tr> </table> </form>
Partager