{changepwdsendmail:reader_slice_id:from_email:username}

Description

Sends a password-reset e-mail to one reader (member) account, identified by username, in a reader slice. This is the non-interactive companion to changepwd: where changepwd renders the self-service forms a visitor clicks through, changepwdsendmail fires the reset e-mail directly for a user you already know. The e-mail carries a time-limited link (valid about two hours) that lets the reader set a new password; if the reader slice has a password change e-mail template, that template is used, otherwise a built-in message is sent. Output is one of three literal strings: 1 when the e-mail was sent, err when the user could not be found or sending failed, and an empty string when the reader slice id is not a valid 32-character id. Because it actually dispatches mail, call it only in response to a real request (for example a form submission), never in a view that re-renders on every page load.

Parameters

reader_slice_id required

The 32-character id of the reader slice (member module) that holds the user accounts. Find it in the slice admin URL. If this is not a valid 32-character id the command does nothing and returns an empty string.

from_email optional default ERROR_REPORTING_EMAIL (the install error reporting address)

The e-mail address put in the From, Reply-To and Errors-To headers of the reset message. Optional: if you leave it empty the install-wide error reporting address (ERROR_REPORTING_EMAIL from config) is used. Has no effect when a password change e-mail template exists for the slice, since the template supplies its own sender.

username required

The login name or e-mail of the reader to send the reset to. The command looks the value up in the reader slice by username first, then by e-mail. If empty or not found, no mail is sent and the command returns err.

Examples

test{strlen:{changepwdsendmail:notanid}}
Expected0
Actual0
When the first argument is not a valid 32-character slice id, the command returns an empty string and sends nothing. Here strlen measures that empty result as 0. This is the safe way to probe the command without dispatching any e-mail.
test{changepwdsendmail:00000000000000000000000000000000}
Expectederr
Actualerr
With a syntactically valid 32-character slice id but no matching user (here the username argument is omitted), no e-mail is sent and the command returns the literal string err. Use this branch to detect a bad or missing user without side effects.
virtual{changepwdsendmail:7cd4b69e8e4e4f4e9b1f9c2d3a5b6c7d:noreply@example.org:jdoe}
Expected1 (and a reset e-mail is sent to the member)
Actualerr
The real-world call: a live reader slice id, a sender address, and the member username. On success it e-mails jdoe a time-limited password reset link and returns 1. This example is illustrative only - it would dispatch a real e-mail, and the slice id and user are install-specific - so it is not run as a test.
virtual{if:{post:do_reset}:{changepwdsendmail:7cd4b69e8e4e4f4e9b1f9c2d3a5b6c7d::{post:login}}:}
Expected1 when the form was submitted with a known login, otherwise empty or err
A practical pattern: only call the command when a form was actually submitted. Here it fires the reset for the login the visitor typed (read with post) and leaves from_email empty so the install error reporting address is used. Request-dependent and side-effecting, so illustrative only.