-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
@@ -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]); | ||
|
||
|