Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 097e15dc authored by Israel Yago Pereira's avatar Israel Yago Pereira
Browse files

Fix checking for env variables for sendgrid

parent 744c011a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ https://welcome.domaina.pw/?authmail=user@email.com&authsecret=password
To be able to use [SendGrid](https://sendgrid.com/) as the email sender, you need to set the following ENV variables:
- `SENDGRID_API_KEY`, something like: "SG.r_l1Ss0aRAB8..."
- `SENDGRID_EMAIL_FROM`, a valid sender email validated on SendGrid
- `SENDGRID_TEMPLATE_ID_EMAIL_CONFIRMATION`, a template id of the email confirmation body to be used. Also created on SendGrid dashboard. ex: "d-47948c4b..."
- `SENDGRID_TEMPLATE_ID_ACCOUNT_CREATED`, a template id of the email sent when the account was created. Also created on SendGrid dashboard. ex: "d-87143d1c..."
- `SENDGRID_TEMPLATE_ID_EMAIL_CONFIRMATION_XX`, a template id of the email confirmation body to be used where XX is a valid language code (EN, FR, ...). Also created on SendGrid dashboard. ex: "d-47948c4b..."
- `SENDGRID_TEMPLATE_ID_ACCOUNT_CREATED_XX`, a template id of the email sent when the account was created where XX is a valid language code (EN, FR, ...). Also created on SendGrid dashboard. ex: "d-87143d1c..."

# License

+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ function respond_with_message($response_code, $message)
function sendWelcomeMail($authmail, $mbox, $domain)
{
    $mailDomain = getMailDomain();
    if (getenv("SENDGRID_API_KEY") !== false) {
    if (!empty(getenv("SENDGRID_API_KEY"))) {
        return sendWelcomeMailWithSendGrid($authmail, $mbox, $domain, $mailDomain);
    }
    return sendWelcomeMailWithPHPMail($authmail, $mbox, $domain, $mailDomain);
+4 −3
Original line number Diff line number Diff line
@@ -34,7 +34,8 @@ function sendInviteMail($to, $secret, $lang)
        $signupURL .= "$lang/";
    }
    $signupURL .= "register?authmail=$encoded_email&authsecret=$secret";
    if (getenv("SENDGRID_API_KEY") !== false) {
    $SENDGRID_API_KEY = getenv("SENDGRID_API_KEY");
    if (!empty($SENDGRID_API_KEY)) {
        return sendInviteMailWithSendGrid($to, $signupURL);
    }
    return sendInviteMailWithPHPMail($to, $signupURL, $lang);
@@ -150,12 +151,12 @@ function getLocalizedEnv(string $envKey, string $lang): string
    $lang = strtoupper($lang);

    $value = getenv("{$envKey}_{$lang}");
    if ($value !== false) {
    if (!empty($value)) {
        return $value;
    }
    // Searching for default value
    $value = getenv("{$envKey}_EN");
    if ($value === false) {
    if (empty($value)) {
        throw new Exception("ENV variable '$envKey' was not found for language '$lang' nor a default value was set");
    }
    return $value;