-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
65 lines (55 loc) · 2.4 KB
/
mail.php
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
<?php
/**
* Send mail if login/password forgotten
*/
require('./inc/config.php');
$smarty->assign('booDisplayMenu', false);
// No $_POST data -> display the blank form
if (!count($_POST)) {
$smarty->caching = true;
if(!$smarty->is_cached('mail.tpl')) {
$smarty->assign('strPageTitle', STR_MAIL_PAGE_TITLE_SILLAJ);
}
$smarty->display('mail.tpl');
}
// else $_POST data -> validate the form : update db and send the mail
else {
// check validity and if email exists in the database
$user->checkEmail($_POST['strEmail']);
// Update the password in the database ; begin a db transaction
// so if the mail fails we can rollback
$db->query('BEGIN');
$arrNewLogin = $user->resetPassword($_POST['strEmail'], false);
// Prepare mail with PHPMailer
require(FN_ROOT_DIR_SILLAJ .'lib/phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->SetLanguage($_SESSION['strLocale'], FN_ROOT_DIR_SILLAJ .'lib/phpmailer/language/');
$mail->isSMTP(); // telling the class to use SMTP
$mail->Host = STR_MAIL_SERVER_SILLAJ; // SMTP server
$mail->Port = STR_MAIL_PORT_SILLAJ; // SMTP port
if (BOO_MAIL_SMTP_AUTHENT_SILLAJ) {
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = STR_MAIL_SMTP_LOGIN_SILLAJ; // SMTP username
$mail->Password = STR_MAIL_SMTP_PASSWORD_SILLAJ; // SMTP password
}
// Build message
$mail->From = STR_ADMIN_EMAIL_SILLAJ;
$mail->FromName = STR_SITE_NAME_SILLAJ;
$mail->addAddress($_POST['strEmail']);
$mail->Subject = '['. STR_SITE_NAME_SILLAJ .'] '. STR_MAIL_SUBJECT_SILLAJ;
$strBody = $_POST['strEmail'] .",\n";
// loop through all accounts if the same email address has been used for several accounts
for ($i=0;$i<count($arrNewLogin);$i++) {
$strBody .= sprintf(STR_MAIL_BODY_SILLAJ, $arrNewLogin[$i]['strUserId'], $arrNewLogin[$i]['strPassword']) ."\n\n";
}
$mail->Body = $strBody ."\nhttp://". $_SERVER['SERVER_NAME'] . URL_ROOT_DIR_SILLAJ;
// Send message
if(!$mail->send()) {
$db->rollback();
raiseError(STR_MAIL_ERROR_SILLAJ .' '. $mail->ErrorInfo);
}
$db->commit();
$smarty->assign('strPageTitle', STR_MAIL_PAGE_TITLE_SILLAJ);
displayMessage(STR_MAIL_SUCCESS_SILLAJ .' '. htmlspecialchars($_POST['strEmail']));
}
?>