@@ -82,6 +82,7 @@ function user_insert($event_name, $data) {
8282 //* get the config
8383 $ app ->uses ('getconf,system ' );
8484 $ mail_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'mail ' );
85+ $ global_mail_config = $ app ->getconf ->get_global_config ('mail ' );
8586
8687 // convert to lower case - it could cause problems if some directory above has upper case name
8788 // $data['new']['maildir'] = strtolower($data['new']['maildir']);
@@ -218,20 +219,30 @@ function user_insert($event_name, $data) {
218219 $ lines = file ($ conf ['rootpath ' ].'/conf/mail/welcome_email_en.txt ' );
219220 }
220221
222+ $ placeholders = array (
223+ '{domain} ' => "$ domain " ,
224+ '{email} ' => $ data ["new " ]["email " ],
225+ '{admin_mail} ' => ($ global_mail_config ['admin_mail ' ] != '' ? $ global_mail_config ['admin_mail ' ] : 'root ' ),
226+ '{admin_name} ' => ($ global_mail_config ['admin_name ' ] != '' ? $ global_mail_config ['admin_name ' ] : '' ),
227+ );
228+
221229 //* Get from address
222230 $ parts = explode (': ' , trim ($ lines [0 ]));
223231 unset($ parts [0 ]);
224232 $ welcome_mail_from = implode (': ' , $ parts );
225233 unset($ lines [0 ]);
234+ $ welcome_mail_from = strtr ($ welcome_mail_from , $ placeholders );
226235
227236 //* Get subject
228237 $ parts = explode (': ' , trim ($ lines [1 ]));
229238 unset($ parts [0 ]);
230239 $ welcome_mail_subject = implode (': ' , $ parts );
231240 unset($ lines [1 ]);
241+ $ welcome_mail_subject = strtr ($ welcome_mail_subject , $ placeholders );
232242
233243 //* Get message
234244 $ welcome_mail_message = trim (implode ($ lines ));
245+ $ welcome_mail_message = strtr ($ welcome_mail_message , $ placeholders );
235246 unset($ tmp );
236247
237248 $ mailHeaders = "MIME-Version: 1.0 " . "\n" ;
@@ -247,8 +258,14 @@ function user_insert($event_name, $data) {
247258 $ mailTarget = $ data ["new " ]["email " ];
248259 $ mailSubject = "=?utf-8?B? " .base64_encode ($ welcome_mail_subject )."?= " ;
249260
250- //* Send the welcome email only on the "master" mail server to avoid duplicate emails
251- if ($ conf ['mirror_server_id ' ] == 0 ) mail ($ mailTarget , $ mailSubject , $ welcome_mail_message , $ mailHeaders );
261+ $ additionalParameters = '' ;
262+ if (preg_match ('/\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63})\b/i ' , $ welcome_mail_from , $ matches )) {
263+ $ additionalParameters = '-f ' .$ matches [1 ];
264+ }
265+
266+ // Send the welcome email only on a "master" mail server to avoid duplicate emails
267+ // (bypass the normal ispcmail class when creating mail accounts)
268+ if ($ conf ['mirror_server_id ' ] == 0 ) mail ($ mailTarget , $ mailSubject , $ welcome_mail_message , $ mailHeaders , $ additionalParameters );
252269
253270 }
254271
0 commit comments