Skip to content

Commit

Permalink
Update subscribe code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Nov 30, 2022
1 parent 5d862f3 commit 8205f03
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
20 changes: 10 additions & 10 deletions dist/subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
* Makes it easy to edit the username, password, port, etc.
* LOAD from a env file that's in the root folder, the template can be found in
* .env.example file
*
* Original: $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
* Changed to put in private folder outside www
*/
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv = Dotenv\Dotenv::createImmutable('/home/codidact/private/');
$dotenv->load();
$constants = array(
"HOST" => $_ENV['HOST'],
"USERNAME" => $_ENV['USERNAME'],
"PASSWORD" => $_ENV['PASSWORD'],
"PORT" => (int)$_ENV['PORT'],
"FROM" => $_ENV['FROM'],
"TO" => $_ENV['TO'],
"DEBUG" => (int)$_ENV['DEBUG']
);

Expand All @@ -53,14 +56,12 @@
* Server settings.
*/
$mail->SMTPDebug = $constants["DEBUG"];
$mail->isSMTP();
$mail->Host = $constants["HOST"];
$mail->SMTPAuth = true;
$mail->Username = $constants["USERNAME"];
$mail->Password = $constants["PASSWORD"];
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = $constants["PORT"];
$mail->SMTPSecure = 'ssl';
/*
* Should be turned on in production.
* $mail->SMTPDebug = false;
Expand All @@ -69,23 +70,22 @@
/*
* Email recipents.
*/
$mail->setFrom($constants["FROM"]);
$mail->addAddress($emailString);
$mail->setFrom($emailString);
$mail->addAddress($constants["TO"]);
/*
Content section. Subject and body goes here.
*/
$mail->Subject = '';
$mail->Body = '';
$mail->Subject = 'Subscription to Codidact email list';
$mail->Body = 'Subscription request for [email protected]';
$mail->AltBody = '';
/*
Send the mail.
*/
$mail->send();
$responseString = "Subscribed!";
$responseString = "Thank you for your subscription request. You should receive an automated message with confirmation instructions.<br><a href=\"https://codidact.org\">Click here to return to Codidact</a>";
echo $responseString;
} catch (Exception $e) {
$err = $mail->ErrorInfo;
$responseString = "Mail was not sent, please report the issue <a href='https://github.com/codidact/landing-page/issues'>here</a>";
echo $responseString;
}

57 changes: 36 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8205f03

Please sign in to comment.