Jump to content
MakeWebGames

GL2 help forgotPassword from_email


Tom V

Recommended Posts

3 hours ago, Eurogangster said:

Find this in the forgotPassword.inc.php if (isset($user["U_id"])) { Under the $body add $headers = "From: [email protected]" ; And you are ready


Find this in the forgotPassword.inc.php

            if (isset($user["U_id"])) {  


Under the $body add

	        $headers = "From: [email protected]" ; 

And you are ready

 

This method would hard-code the email address. OP wants to use the dynamically-set address in the site settings.
I'm not massively familiar with GL, so I can't advise further

Link to comment
Share on other sites

I tried adding this to the allowed methods:       'from_email'=>array('type'=>'get')

I added this to constructModule:                  $this->page->addToTemplate("from_email", $settings->loadSetting("from_email"));
     

Then I added this: 

$from = $this->methodData->from_email; 
$headers[]= 'From:'.$from;

 

And I changed this line to this:    mail($user["U_email"], "Password Reset", $body, implode("\r\n", $headers));

 

The result is the email that is sent goes to spam folder, because the from address shows up as (unknown sender).  This is where I'm stuck.

Link to comment
Share on other sites

public function method_reset() {
    $this->error("A password reset email has been sent to you!", "success");
    $user = $this->db->select("SELECT * FROM users INNER JOIN userStats ON (US_id = U_id) WHERE U_email = :email ORDER BY U_id DESC", array(":email" => $this->methodData->email));
    if (isset($user["U_id"])) {
    $url = $_SERVER["HTTP_ORIGIN"] . $_SERVER["SCRIPT_NAME"] . "?page=forgotPassword&action=resetPassword&auth=" . $user["U_password"] . "&id=" . $user["U_id"] . "";
    $settings = new settings();
    $from = $settings
    $headers['From'] = $settings->loadSetting('from_email');
    $body = "To reset your password please follow the link below: \r\n " . $url;
    mail($user["U_email"], "Password Reset", $body, $headers);

}

        }

Try that. 
Edit: I’m on mobile and it’s real difficult to edit my code I pasted but delete the entire line that says $from = $settings

Edited by KyleMassacre
  • Like 2
Link to comment
Share on other sites

if (isset($user["U_id"])) {

    $url = $_SERVER["HTTP_ORIGIN"] . $_SERVER["SCRIPT_NAME"] . "?page=forgotPassword&action=resetPassword&auth=" . $user["U_password"] . "&id=" . $user["U_id"] . "";
    $settings = new settings();
    $headers["From"] = "From: ";
    $headers['From'] .= $settings->loadSetting('from_email');
    $body = "To reset your password please follow the link below: \r\n " . $url;
    mail($user["U_email"], "Password Reset", $body, $headers['From']);

}

Made a small change so that the array value is formatted correctly. Tested and this solution is working! thank you KyleMassacre

Link to comment
Share on other sites

5 hours ago, TonyCisseroni said:

Made a small change so that the array value is formatted correctly.

Based off the docs, it is formatted correctly if you are using v7.2 which I should've verified. To make it more universal, it should really be like this:

public function method_reset() {
    $this->error("A password reset email has been sent to you!", "success");
    $user = $this->db->select("SELECT * FROM users INNER JOIN userStats ON (US_id = U_id) WHERE U_email = :email ORDER BY U_id DESC", array(":email" => $this->methodData->email));
    if (isset($user["U_id"])) {
    $url = $_SERVER["HTTP_ORIGIN"] . $_SERVER["SCRIPT_NAME"] . "?page=forgotPassword&action=resetPassword&auth=" . $user["U_password"] . "&id=" . $user["U_id"] . "";
    $settings = new settings();
    $headers = null;
    if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
        $headers['From'] = $settings->loadSetting('from_email');
        $headers['MIME-Version'] = '1.0';
        $headers['Content-type'] = 'text/html; charset=iso-8859-1';
    }
    else {
        $headers = 'From: '.$settings->loadSetting('from_email').'\r\n'.
            'MIME-Version: 1.0 \r\n'.
            'Content-type: text/html; charset=iso-8859-1 \r\n';
    }
    $body = "To reset your password please follow the link below: \r\n <a href='{$url}'>Click Here</a>" \r\n;
    $body .= "If the link is not visible, then follow this url below: \r\n {$url}"
    mail($user["U_email"], "Password Reset", wordwrap($body, 70, "\r\n"), $headers);

}

 

Edited by KyleMassacre
Updated code for mistake in else statement. PHP < 7.2 does not allow an array for headers
Link to comment
Share on other sites

Sorry for the confusion. I meant to format the value in the array as "From: [email protected]" instead of just the email. The mail function needs it that way.

Also if you look at the mail function you have to call $headers['From'] or you will get an error because it's looking for a string value not an array.

The code I posted is tested and working. 

Link to comment
Share on other sites

56 minutes ago, TonyCisseroni said:

Sorry for the confusion. I meant to format the value in the array as "From: [email protected]" instead of just the email. The mail function needs it that way.

Also if you look at the mail function you have to call $headers['From'] or you will get an error because it's looking for a string value not an array.

The code I posted is tested and working. 

I did it again, didn’t I lol. It’s not supposed to be an array in the else statement. Updated post

Edited by KyleMassacre
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...