mirror of
https://github.com/wheelybird/ldap-user-manager.git
synced 2025-01-18 15:32:54 +01:00
Custom email body (#51)
* get email body from ENV * read subject from env * html mail * replace special string with username and password * missing ; * more str_replace * utf8 in mail * typo * docs * fix var * count accounts * fix print
This commit is contained in:
parent
65bee01fad
commit
b33ff26fd2
19
README.md
19
README.md
@ -156,11 +156,24 @@ To send emails you'll need to use an existing SMTP server. Email sending will b
|
||||
|
||||
* `EMAIL_FROM_NAME` (default: *`SITE_NAME`*): The FROM name used when sending out emails. The default name is taken from `SITE_NAME` under **Organisation settings**.
|
||||
|
||||
* `MAIL_SUBJECT` (default: Your $ORGANISATION_NAME account has been created.): The mail subject
|
||||
|
||||
* `MAIL_BODY` (default: ): The mail body. You can use the following substring in the body which will be replaced by user info:
|
||||
|
||||
- `#username#`: the user username
|
||||
- `#first_name#`: the user first name
|
||||
- `#last_name#`: the user last name
|
||||
- `#password#`: the user password
|
||||
|
||||
**Account requests**
|
||||
|
||||
#### Account request settings
|
||||
|
||||
* `ACCOUNT_REQUESTS_ENABLED` (default: *FALSE*): Set to TRUE in order to enable a form that people can fill in to request an account. This will send an email to `ACCOUNT_REQUESTS_EMAIL` with their details and a link to the account creation page where the details will be filled in automatically. You'll need to set up email sending (see **Email sending**, above) for this to work. If this is enabled but email sending isn't then requests will be disabled and an error message sent to the logs.
|
||||
|
||||
* `ACCOUNT_REQUESTS_EMAIL` (default: *`EMAIL_FROM_ADDRESS`*): This is the email address that any requests for a new account are sent to.
|
||||
* `ACCOUNT_REQUESTS_ENABLED` (default: *FALSE*): Set to TRUE in order to enable a form that people can fill in to request an account. This will send an email to `ACCOUNT_REQUESTS_EMAIL` with their details and a link to the account creation page where the details will be filled in automatically. You'll need to set up email sending (see **Email sending**, above) for this to work. If this is enabled but email sending isn't then requests will be disabled and an error message sent to the logs.
|
||||
|
||||
* `ACCOUNT_REQUESTS_EMAIL` (default: *{EMAIL_FROM_ADDRESS}*): This is the email address that any requests for a new account are sent to.
|
||||
|
||||
**Site security settings**
|
||||
|
||||
#### Website security
|
||||
|
||||
|
@ -51,6 +51,10 @@ $people = ldap_get_user_list($ldap_connection);
|
||||
|
||||
?>
|
||||
<div class="container">
|
||||
<div>
|
||||
<p><?php print count($people);?> accounts</p>
|
||||
</div>
|
||||
|
||||
<form action="/<?php print $THIS_MODULE_PATH; ?>/new_user.php" method="post">
|
||||
<button id="add_group" class="btn btn-default" type="submit">New user</button>
|
||||
</form>
|
||||
|
@ -121,9 +121,9 @@ if (isset($_POST['create_account'])) {
|
||||
|
||||
if (isset($send_user_email) and $send_user_email == TRUE) {
|
||||
|
||||
$mail_subject = "Your $ORGANISATION_NAME account has been created.";
|
||||
$mail_subject = getenv('MAIL_SUBJECT') ?: "Your $ORGANISATION_NAME account has been created.";
|
||||
|
||||
$mail_body = <<<EoT
|
||||
$mail_body = getenv('MAIL_BODY') ?: <<<EoT
|
||||
You've been set up with an account for $ORGANISATION_NAME. Your credentials are:
|
||||
|
||||
Username: $account_identifier
|
||||
@ -132,6 +132,12 @@ Password: $password
|
||||
You should change your password as soon as possible. Go to ${SITE_PROTOCOL}${SERVER_HOSTNAME}/change_password and log in using your new credentials. This will take you to a page where you can change your password.
|
||||
EoT;
|
||||
|
||||
// Replace special substring with user variables (substring are used in env)
|
||||
$mail_body = str_replace("#username#", $account_identifier, $mail_body);
|
||||
$mail_body = str_replace("#first_name#", $givenname, $mail_body);
|
||||
$mail_body = str_replace("#last_name#", $sn, $mail_body);
|
||||
$mail_body = str_replace("#password#", $password, $mail_body);
|
||||
|
||||
include_once "mail_functions.inc.php";
|
||||
$sent_email = send_email($mail,"$first_name $last_name",$mail_subject,$mail_body);
|
||||
$creation_message = "The account was created";
|
||||
|
@ -9,6 +9,7 @@ function send_email($recipient_email,$recipient_name,$subject,$body) {
|
||||
global $EMAIL, $SMTP, $log_prefix;
|
||||
|
||||
$mail = new PHPMailer\PHPMailer\PHPMailer();
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->isSMTP();
|
||||
|
||||
$mail->SMTPDebug = $SMTP['debug_level'];
|
||||
@ -29,6 +30,7 @@ function send_email($recipient_email,$recipient_name,$subject,$body) {
|
||||
$mail->addAddress($recipient_email, $recipient_name);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $body;
|
||||
$mail->IsHTML(true);
|
||||
|
||||
if (!$mail->Send()) {
|
||||
error_log("$log_prefix SMTP: Unable to send email: " . $mail->ErrorInfo);
|
||||
|
Loading…
x
Reference in New Issue
Block a user