The following code is what I'm using to send a password reset email. The specific part I'm referring to is how I'm setting $message
. Would there be a cleaner way to do this or is this about as clean as you can get?
/**
* Attempt to send reset link
* @return bool True if success, false if not
*/
public function try() {
// Update users email hash
$this->_updateResetHash();
$user = $this->_grabUser();
$resetLink = $_SERVER["HTTP_ORIGIN"] . "/reset/" . $this->_hash . "/" . $user['uid'];
$message = "Hello, " . ucfirst($user["first_name"]) . ", <br /><br />";
$message .= "We received a request to reset your password. <br /><br />";
$message .= "<a href=\"" . $resetLink . "\">Please click here to reset your password</a><br />";
$message .= "<h4>If you did not make this request you do not need to worry. The only way your password can be reset is through the email that is on the account. Unless someone has taken control of you email, your account is safe and no one except you can gain access.</h4>";
// If email is sent
if (!Mail::send("Password reset link", $message, ["no-reply@.com" => "No-Reply@"], $this->_email, 'text/html')) {
return false;
}
return true;
}
Also, I'm not too sure how or if it exists but I heard somewhere that Twig / Slim, which I'm using, have a way of using templates for swiftmailer.
try
? \$\endgroup\$