Skip to content

Commit

Permalink
PHPMailer for registration
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Jul 20, 2023
1 parent edce0c2 commit 1c63916
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions source/Server/createuser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php
require './helpers.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require './helpers.php';
require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';

$db = connectToDB();
$db->begin_transaction();

Expand Down Expand Up @@ -36,13 +42,41 @@
$success = false;
if ($db->query("INSERT INTO user (ID, NAME, PW_HASH, EMAIL_HASH, SALT, ACTIVATION_CODE, FLAGS, TIMESTAMP)
VALUES (NULL, '".addslashes($userName)."', '".addslashes($pwHash)."', '".addslashes($emailHash)."', '".addslashes($salt)."', '$activationCode', 0, NULL)")) {
$success = true;

mail(
$email,
"Artificial Life Environment: confirmation code for user '" . addslashes($userName) . "'",
"Your confirmation code for user '".addslashes($userName)."' is:\n\n" . $activationCode,
"From: user registration <[email protected]>");
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
//$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'alfa3211.alfahosting-server.de'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[username]'; // SMTP username
$mail->Password = '[password]'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable SSL encryption, TLS also accepted with port 465
$mail->Port = 465; // TCP port to connect to

//Recipients
$mail->setFrom('[email protected]', 'User registration'); //This is the email your form sends From
$mail->addAddress($email, ''); // Add a recipient address
//$mail->addAddress('[email protected]'); // Name is optional
//$mail->addReplyTo('[email protected]', 'Information');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');

//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name

//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Artificial Life Environment: confirmation code for user '" . addslashes($userName) . "'";
$mail->Body = "Your confirmation code for user '".addslashes($userName)."' is:\n\n" . $activationCode;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
$success = true;
} catch (Exception $e) {
$success = false;
}
}
echo json_encode(["result"=>$success]);

Expand Down

0 comments on commit 1c63916

Please sign in to comment.