Bonjour,
Je rencontre un problème sur l'envoi d'email par PHPMailer depuis que j'ai fait des modifications sur la page contact.
Contexte :
J'avais une liste déroulante de plusieurs services d'entreprise ; chaque service était associé à une adresse email, ceci afin de cacher l'adresse de l'extérieur. Suite à un changement de stratégie interne, j'ai fait sauter cette liste déroulante puisque désormais nous n'utiliserons qu'une seule adresse email pour la réception de tous les messages provenant de la page web de contact.
Bien qu'il me semble avoir réalisé les modifications nécessaires dans mes scripts, cela ne fonctionne plus.
Erreur renvoyée par la page contact :
Je tourne en rond sans parvenir à identifier le problème. Je pense pourtant avoir vérifié l'existante et la valeur correcte des constantes, des variables de session ...Could not instantiate mail function.
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: Could not instantiate mail function. in /var/www/update/views/include/classes/phpmailer/src/PHPMailer.php:1671 Stack trace: #0 /var/www/update/views/include/classes/phpmailer/src/PHPMailer.php(1483): PHPMailer\PHPMailer\PHPMailer->mailSend('Date: Tue, 23 O...', '<html>\n ...') #1 /var/www/update/views/include/classes/phpmailer/src/PHPMailer.php(1320): PHPMailer\PHPMailer\PHPMailer->postSend() #2 /var/www/update/views/include/functions/sendemail.php(273): PHPMailer\PHPMailer\PHPMailer->send() #3 /var/www/update/controllers/treatments/contact-action.php(321): sendEmail() #4 /var/www/update/views/include/html-header.class.php(94): require_once('/var/www/update...') #5 /var/www/update/views/View.class.php(76): HTMLHeader->getHTMLHeader(Object(stpalais\models\dto\ContentDto), '') #6 /var/www/update/controllers/FrontController.class.php(463): View->render(Object(stpalais\models\dto\ContentDto), '', '', Array, '', '') #7 /var/www/update/index.php(64): FrontController->r in /var/www/update/views/include/classes/phpmailer/src/PHPMailer.php on line 1671
Merci de m'aider à décortiquer ce problème.
J'ai laissé en commentaire dans les codes ci-dessous la partie de script modifiée.
Script traitant les données du formulaire "contact-action.php" :
Script traitant le mail à envoyer (mise en forme, contacts, envoi) "sendemail.php" :
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328 <?php /* ** Definition of variables */ // Number of recipients $numberOfRecipients = 16; // Index of the recipient by default $defaultRecipientID = 1; /* * Filtering variables */ $code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_SPECIAL_CHARS); $lastname = filter_input(INPUT_POST, 'lastname', FILTER_SANITIZE_SPECIAL_CHARS); $firstname = filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_SPECIAL_CHARS); $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_SPECIAL_CHARS); $object = filter_input(INPUT_POST, 'object', FILTER_SANITIZE_SPECIAL_CHARS); $body = filter_input(INPUT_POST, 'body', FILTER_SANITIZE_SPECIAL_CHARS); $antispam = filter_input(INPUT_POST, 'antispam', FILTER_SANITIZE_SPECIAL_CHARS); /* $service = filter_input(INPUT_GET, 'service', FILTER_SANITIZE_SPECIAL_CHARS); $recipient = filter_input(INPUT_POST, 'recipient', FILTER_SANITIZE_SPECIAL_CHARS); */ /* ** Checking if the antispam message has been defined ** This message will be displayed in the antispam field of the contact form */ if (isset($code)) { $_SESSION['antispamMsg'] = $code; } else { $_SESSION['antispamMsg'] = ''; } /* ** Checking if the recipient was specified in the URI ** (this is the case if the "envoyer un email" link was clicked in the "services municipaux" page) ** If this is the case, Then ** - the previously created session's recipient is destroyed ** - the default recipient Index is changed to the regarding service. */ /* if (isset($service)) { unset ($_SESSION['recipient']); switch ($service) { case ACCUEIL : $defaultRecipientID = 1 ; break; case CENTRENAUTIQUE : $defaultRecipientID = 2 ; break; case CCAS : $defaultRecipientID = 3 ; break; case COMMERCE : $defaultRecipientID = 4 ; break; case COMMUNICATION : $defaultRecipientID = 5 ; break; case COMPTA : $defaultRecipientID = 6 ; break; case CONSERVATOIRE : $defaultRecipientID = 7 ; break; case CULTURE : $defaultRecipientID = 8 ; break; case ALSH : $defaultRecipientID = 9 ; break; // Contentieux = Foncier as service case FONCIER : $defaultRecipientID = 10 ; break; case CONTENTIEUX : $defaultRecipientID = 10 ; break; case INFORMATIQUE : $defaultRecipientID = 11 ; break; case POLICE : $defaultRecipientID = 12 ; break; case RH : $defaultRecipientID = 13 ; break; case SG : $defaultRecipientID = 14 ; break; case ST : $defaultRecipientID = 15 ; break; case URBA : $defaultRecipientID = 16 ; break; } } */ /* ** Initializing SESSION variables for display into form */ if (!isset($_SESSION['lastname'])) { $_SESSION['lastname'] = ''; } if (!isset($_SESSION['firstname'])) { $_SESSION['firstname'] = ''; } if (!isset($_SESSION['email'])) { $_SESSION['email'] = ''; } if (!isset($_SESSION['object'])) { $_SESSION['object'] = ''; } if (!isset($_SESSION['body'])) { $_SESSION['body'] = ''; } /* if (!isset($_SESSION['recipient'])) { // the option 1 is the default option for ($i=1;$i<=$numberOfRecipients;$i++) { if ($i!=$defaultRecipientID) { $_SESSION['recipient'][$i] = ''; } else { $_SESSION['recipient'][$i] = 'selected="selected" '; } } } else { // by default, the selected option is 'accueil' // if any other valid option was declared as the recipient, then this option is the selected one // and the 'accueil' option is declared as not selected for ($i=1;$i<=$numberOfRecipients;$i++) { if ( ($_SESSION['recipient'][$i] == 'selected="selected" ') && ($i != $defaultRecipientID) ) { $_SESSION['recipient'][$defaultRecipientID] = ''; } elseif ($_SESSION['recipient'][$i] != 'selected="selected" ') { $_SESSION['recipient'][$i] = ''; } } } */ if (!isset($_SESSION['emailErrMsg'])) { $_SESSION['emailErrMsg'] = ''; } /* ** Check if the captcha code is correct ** after the contact form's "send button" was clicked ** ** If correct then redirect to the scripts that sends the email ** If not and code not defined then redirect to the contact form ** The code is defined after the form was submitted. If not defined, it means the form is displayed for the first time. */ $captchaMsg = 'ok'; // If the form was submitted // If not, it means the page has been requested from the 'services municipaux' page if (isset($_REQUEST['submit'])) { // If the user entered a code if (!empty($_REQUEST['antispam'])) { // Conversion into uppercase $code = strtoupper($_REQUEST['antispam']); // Encryption and comparison with the code into $_SESSION['captcha'] if ( md5($code) != $_SESSION['captcha'] ) { $captchaMsg = 'incorrect'; } } else { $captchaMsg = 'vide'; } // Transferring POST variables into SESSION variables for display into form or confirmation message if (isset($lastname)) { $_SESSION['lastname'] = String2html($lastname); } else { $_SESSION['lastname'] = ''; } if (isset($firstname)) { $_SESSION['firstname'] = String2html($firstname); } else { $_SESSION['firstname'] = ''; } if (isset($email)) { $_SESSION['email'] = String2html($email); } else { $_SESSION['email'] = ''; } if (isset($object)) { $_SESSION['object'] = String2html($object); } else { $_SESSION['object'] = ''; } if (isset($body)) { $_SESSION['body'] = String2html($body); } else { $_SESSION['body'] = ''; } if (isset($antispam)) { $_SESSION['antispam'] = String2html($antispam); } else { $_SESSION['antispam'] = ''; } // Inclusion of emails details require_once 'views/include/emailaddr-list.php'; $_SESSION['recipientemail'] = EMAIL_MAIRIE; $_SESSION['recipientservice'] = MAIRIE; /* if (isset($recipient)) { // INCLUSION AND EMAILS DETAILS require_once 'views/include/emailaddr-list.php'; // by default, the selected option is 'accueil' // if any other valid option was declared as the recipient, then this option is the selected one // and the 'accueil' option is declared as not selected $_SESSION['recipient'][1] = 'selected="selected" '; switch ($recipient) { // CENTRE NAUTIQUE case 'centrenautique' : $_SESSION['recipient'][2] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_NAUTIQUE; $_SESSION['recipientservice'] = 'le centre nautique'; break; // CCAS case 'ccas' : $_SESSION['recipient'][3] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_CCAS; $_SESSION['recipientservice'] = 'le centre communal d&action sociale'; break; // COMMERCE case 'commerce' : $_SESSION['recipient'][4] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_COMMERCE; $_SESSION['recipientservice'] = 'le service commerce'; break; // COMMUNICATION case 'communication' : $_SESSION['recipient'][5] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_COMMUNICATION; $_SESSION['recipientservice'] = 'le service communication'; break; // COMPTABILITE case 'comptabilite' : $_SESSION['recipient'][6] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_COMPTA; $_SESSION['recipientservice'] = 'le service comptabilité'; break; // CONSERVATOIRE case 'conservatoire' : $_SESSION['recipient'][7] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_CONSERVATOIRE; $_SESSION['recipientservice'] = 'le conservatoire'; break; // CULTURE & EVENEMENTIEL case 'culture' : $_SESSION['recipient'][8] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_CULTURE; $_SESSION['recipientservice'] = 'le service culture & événementiel'; break; // ENFANCE & JEUNESSE case 'enfance' : $_SESSION['recipient'][9] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_ALSH; $_SESSION['recipientservice'] = 'le service enfance & jeunesse'; break; // FONCIER case 'foncier' : $_SESSION['recipient'][10] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_FONCIER; $_SESSION['recipientservice'] = 'le service foncier'; break; // CONTENTIEUX case 'contentieux' : $_SESSION['recipient'][10] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_CONTENTIEUX; $_SESSION['recipientservice'] = 'le service contentieux'; break; // INFORMATIQUE case 'informatique' : $_SESSION['recipient'][11] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_INFORMATIQUE; $_SESSION['recipientservice'] = 'le service informatique'; break; // POLICE MUNICIPALE case 'police' : $_SESSION['recipient'][12] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_POLICE; $_SESSION['recipientservice'] = 'la police municipale'; break; // PERSONNEL RH case 'rh' : $_SESSION['recipient'][13] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_RH; $_SESSION['recipientservice'] = 'le service du personnel'; break; // SECRETARIAT GENERAL case 'sg' : $_SESSION['recipient'][14] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_SG; $_SESSION['recipientservice'] = 'le secrétariat général'; break; // SERVICES TECHNIQUES case 'st' : $_SESSION['recipient'][15] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_ST; $_SESSION['recipientservice'] = 'les services techniques'; break; // URBANISME case 'urbanisme' : $_SESSION['recipient'][16] = 'selected="selected" '; $_SESSION['recipient'][$defaultRecipientID] = ''; $_SESSION['recipientemail'] = EMAIL_URBA; $_SESSION['recipientservice'] = 'le service urbanisme'; break; // ACCUEIL // which is the default case case 'accueil' : default : $_SESSION['recipient'][1] = 'selected="selected" '; $_SESSION['recipientemail'] = EMAIL_ACCUEIL; $_SESSION['recipientservice'] = 'l'accueil'; } } */ // If the Captcha code is wrong, then redirect to the contact form // Else // - verify the email address is valid // - send the email to the recipients // - redirect to the confirmation page if ($captchaMsg != 'ok') { header("Location: /?page=".CONTACT."&code=".$captchaMsg); } // Correct Captcha code else { // If the email address is valid then // - send the email to the recipients // - redirect to the confirmation page // Else reload the contact page with an email error message require_once 'views/include/functions/checkemail.php'; $_SESSION['emailErrMsg'] = checkEmail($_SESSION['email']); // Valid Email Address if ($_SESSION['emailErrMsg']==-1) { // inclusion of the sending function require 'views/include/functions/sendemail.php'; // redirecting to the confirmation page after creating and sending the email header("Location: /?page=contact-confirmation&envoi=".sendEmail()); } // Invalid Email Address else { header("Location: /?page=".CONTACT."&emailErrMsg=1"); } } }
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290 <?php /************************************************************************************************************************* FUNCTION TO SEND AN EMAIL TO BOTH THE SENDER AND RECIPIENT Author : Stéphane-Hervé Forum : http://inforezo.1fr1.net Email : shinfo17 [at] gmail [dot] com Description : This function sends the email written by the sender to the recipient and sends a copy of this email to the sender himself as a confirmation one. Parameter : - none : the elements of the email are defined in session variables. Return value : - boolean : true (if email sent successfully), false (if something went wrong) **************************************************************************************************************************/ use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; function sendEmail () { echo '<h1>in sendEmail ()</h1>'."\n"; /* INCLUSION OF HTML ENTITIES FUNCTIONS */ require_once 'views/include/functions/accents.php'; /* INCLUSION OF STYLES */ //require_once 'views/include/functions/sendemail.css.php'; require_once 'sendemail.css.php'; /* INCLUSION OF SMTP AND EMAILS DETAILS */ require_once 'views/include/SMTP-details.php'; require_once 'views/include/emailaddr-list.php'; /* INCLUSION OF THE PHPMAILER CLASS to send emails */ //require_once 'views/include/classes/phpmailer/src/class.phpmailer.php'; require_once 'views/include/classes/phpmailer/src/PHPMailer.php'; require_once 'views/include/classes/phpmailer/src/SMTP.php'; require_once 'views/include/classes/phpmailer/src/Exception.php'; /* FOR is played twice so as to send the email : 1- to the civil servant 2- to the visitor so as to confirm */ $count = 1; for ( $count==1;$count<=2;$count++ ) { #################### # SENDING BY EMAIL # #################### // Creation of the PHP Mailer with exceptions enabled $mail = new PHPmailer(true); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// # CREATION OF THE EMAIL HEADERS # //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// // sending by SMTP host with authentication //$mail->IsSMTP(); $mail->IsMail(); // HTML format $mail->IsHTML(MAILHTMLVALUE); // SMTP debug $mail->SMTPDebug=SMTPDEBUG; // SMTP host $mail->Host=SMTP; $mail->Port=SMTPPORT; $mail->SMTPAuth=SMTPAUTH; $mail->Username=SMTPUSERNAME; $mail->Password=SMTPPASSWORD; // SENDING TO THE RECIPIENT if ( $count==1 ) { // Sender = visitor $mail->setFrom(String2Normal($_SESSION['email']), String2Normal($_SESSION['firstname']).' '.String2Normal($_SESSION['lastname']), true); // Recipient = civil service $mail->addAddress($_SESSION['recipientemail']); // Civil Service email address // Visitor's reply email address $mail->addReplyTo($_SESSION['email']); // Subject $mail->Subject='[Website] - '.String2Normal($_SESSION['object']); echo '<h2>in SENDING TO THE RECIPIENT</h2>'."\n" . 'From : '.$mail->From.'<br />'."\n" . 'From : '.$mail->FromName.' ('.$_SESSION['firstname'].' '.$_SESSION['lastname'].')<br />'."\n" . 'To : '.$_SESSION['recipientemail'].'<br />'."\n" . 'Reply to : '.$_SESSION['email'].'<br />'."\n" . 'Subject : '.$mail->Subject.'<br />'."\n" ; } // SENDING TO THE VISITOR else { // Sender = civil servant $mail->From=String2Normal($_SESSION['recipientemail']); $mail->FromName=String2Normal($_SESSION['recipientservice']).' de '.String2Normal(CORPORATENAME); // Recipient = visitor $mail->AddAddress($_SESSION['email']); // Civil servant's reply email address $mail->AddReplyTo($_SESSION['recipientemail']); // Subject $mail->Subject=String2Normal($_SESSION['object']); echo '<h2>in SENDING TO THE VISITOR</h2>'."\n"; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// # CREATION OF THE EMAIL BODY # //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// // CREATION OF THE COMMON PART OF THE HEADER AND BODY $header = '<html>'; $header .= ' <head> <title>'.CORPORATENAME.'</title> '.$style.' </head> <body> '; // IDENTIFICATION OF THE TOWN HALL $body = ' <div id="arriereplan" style="margin:0 auto;padding:40px;width:470px;text-align:center;background:#e9e9e9;border:1px solid #777;"> <div id="fondPage" style="margin:0 auto;padding:20px;width:420px;text-align:center;background:#fff;"> <div id="logo" style="text-align:center;"> <a style="margin:0 auto;font-weight:normal;font-size:12px;color:#000;text-decoration:none;" href="'.SERVERHTTP.'/index.php?page=accueil" title="Ville de Saint-Palais-sur-Mer">'. // LOGO ' <img style="width:265px;height:46px;border:0;" src="'.SERVERHTTP.'/views/design/logo.png" alt="Logo de Saint-Palais-sur-Mer" /> </a> </div> <div id="mesCoordonnees" style="margin:0 auto 30px auto;"> <ul style="font-weight:bold;"> <li style="margin-top:10px;list-style-type:none;text-align:left;font-size:12px;">'.CORPORATENAME.'</li> <li class="identite" style="margin-top:10px;list-style-type:none;text-align:left;font-size:14px;font-weight:bold;">'.$_SESSION['recipientservice'].'</li> <li style="list-style-type:none;text-align:left;font-size:12px;">'.ADDRESS.'</li> <li style="list-style-type:none;text-align:left;font-size:12px;">'.CITY.'</li> <li style="list-style-type:none;text-align:left;font-size:12px;">Tél. '.TEL.'</li> <li style="list-style-type:none;text-align:left;font-size:12px;"> Web : <a style="font-weight:normal;font-size:12px;color:#000;text-decoration:none;" href="'.WEBADDRESS.'"'. 'title="">'.WEBADDRESS.'</a> </li> </ul> </div> '; // IDENTIFICATION OF THE VISITOR $body .= ' <div id="vosCoordonnees"> <ul style="margin:0;padding:0 0 0 55%;width:95%;text-align:left;"> <li class="identite" style="margin-top:10px;list-style-type:none;font-size:14px;font-weight:bold;">'.$_SESSION['firstname'].' '.$_SESSION['lastname'].'</li> <li style="list-style-type:none;font-size:12px;"> Email : <a style="font-weight:normal;font-size:12px;color:#000;text-decoration:none;" href="mailto:'.$_SESSION['email'].'"'. 'title="">'.$_SESSION['email'].'</a> </li> </ul> </div> '; // CREATION OF THE BODY ... // ... BOUND TO THE CIVIL SERVANT if ( $count===1 ) { $body .= ' <div id="message"> <p style="text-align:left;">'. $_SESSION['firstname'].' '.$_SESSION['lastname'].' vous envoie ce message le '. // date = 'Day, DD Mmm YYYY à HHh MMm SS' as 'Monday, 01 Jan 2014 à 15h 10m 00' date('l, d M Y').' à '.date('G\h i\m s').' : '. '</p> <p id="votreMessage" style="padding:12px 5px;text-align:left;border:1px solid #777;">'.String2Normal($_SESSION['body']).'</p> </div> '; } // ... BOUND TO THE VISITOR else { // If the email was sent successfully to the civil service then add the confirmation message, // If not then add the error message. if ($success === true) { $body .= ' <div id="message"> <p id="bonjour" style="margin:30px 0;text-align:left;">Bonjour '.$_SESSION['firstname'].' '.$_SESSION['lastname'].',</p> <p style="text-align:left;">Votre message a bien été envoyé vers '.$_SESSION['recipientservice'].', vous en recevrez une réponse rapidement.</p> <p id="ceMessage" style="margin:20px 0;width:90%;">Voici une copie de ce message : </p> <p id="votreMessage" style="padding:12px 5px;text-align:left;border:1px solid #777;">'.String2Normal($_SESSION['body']).'</p> <hr class="HiddenSepar20em" /> </div> '; } elseif ($success === false) { $body .= ' <div id="message"> <p id="bonjour" style="margin:30px 0;">Bonjour '.$_SESSION['firstname'].' '.$_SESSION['lastname'].',</p> <p>Votre message n'a pas pu être envoyé vers '.$_SESSION['recipientservice'].'. Veuillez nous excuser pour ce désagrément. Si le problème persiste, nous vous prions de bien vouloir le signaler à notre Service Informatique.</p> <p id="ceMessage">Voici une copie de votre message : </p> <p id="votreMessage">'.$_SESSION['body'].'</p> <hr class="HiddenSepar40em" /> </div> '; } } $body .= ' </div> </div> '; $end =' </body> </html> '; //~~~~~~~~~~~~~~~~~~~~~~~~~~// # SENDING THE EMAIL # //~~~~~~~~~~~~~~~~~~~~~~~~~~// $mail->Body = $header.$body.$end; $_SESSION['mail_body'] = '<p id="votreMessage">'.String2Normal($_SESSION['body']).'</p>'; echo '<h2>in SENDING THE EMAIL</h2>'."\n" . $mail->Body."\n" ; //$mailsuccess = $mail->Send(); $mailsuccess = $mail->send(); // Then the value of the email sending function is the value that will be returned as success. // It is more important to know if the email could be sent to the Service that to know if it could be sent to the sender // That's why we check the success of the first sending. if ($count===1) { $success = $mailsuccess; } } // closing the SMTP connexion $mail->SmtpClose(); // destroying the useless email variables unset($mail,$header,$style,$body,$end,$count,$mailsuccess); // exit returning the boolean value return $success; }
Partager