Fix empty emails being sent
This commit is contained in:
parent
feb2f7d2f5
commit
5edd844c2c
3 changed files with 26 additions and 42 deletions
|
@ -60,30 +60,17 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
/** Send email */
|
||||
$user = new User($wishlist['user']);
|
||||
$email = new Email($user->email, __('Wish request'), 'default', 'wishlist-request-wishes');
|
||||
$email->mjml = str_replace(
|
||||
'TEXT_HELLO',
|
||||
__('Hello,'),
|
||||
$email->mjml
|
||||
);
|
||||
$email->mjml = str_replace(
|
||||
$email->setPlaceholder('TEXT_HELLO', __('Hello,'));
|
||||
$email->setPlaceholder(
|
||||
'TEXT_WISHLIST_REQUEST_WISHES',
|
||||
sprintf(
|
||||
/** TRANSLATORS: %s: Wishlist name */
|
||||
__('somebody has requested that you add more wishes to your wishlist %s.'),
|
||||
'<a href="' . $href . '">' . $wishlist['name'] . '</a>'
|
||||
),
|
||||
$email->mjml
|
||||
);
|
||||
$email->mjml = str_replace(
|
||||
'TEXT_WISH_ADD',
|
||||
__('Add wish'),
|
||||
$email->mjml
|
||||
);
|
||||
$email->mjml = str_replace(
|
||||
'LINK_WISH_ADD',
|
||||
$href . '&wish_add=true',
|
||||
$email->mjml
|
||||
)
|
||||
);
|
||||
$email->setPlaceholder('TEXT_WISH_ADD', __('Add wish'));
|
||||
$email->setPlaceholder('LINK_WISH_ADD', $href . '&wish_add=true');
|
||||
|
||||
$success = $email->send();
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@ use Qferrer\Mjml\Renderer\ApiRenderer;
|
|||
|
||||
class Email
|
||||
{
|
||||
public string $mjml;
|
||||
private string $mjml = '';
|
||||
private string $contentsTemplate;
|
||||
private string $contentsPart;
|
||||
|
||||
public function __construct(
|
||||
private string $to,
|
||||
|
@ -24,8 +26,15 @@ class Email
|
|||
private string $template,
|
||||
private string $part
|
||||
) {
|
||||
$this->mjml = file_get_contents(ROOT . '/src/mjml/' . $this->template . '.mjml');
|
||||
$this->mjml = str_replace('MJML_PART', 'parts/' . $this->part . '.mjml', $this->mjml);
|
||||
$this->contentsTemplate = file_get_contents(ROOT . '/src/mjml/' . $this->template . '.mjml');
|
||||
$this->contentsPart = file_get_contents(ROOT . '/src/mjml/parts/' . $this->part . '.mjml');
|
||||
|
||||
$this->mjml = str_replace('<mj-include path="MJML_PART" />', $this->contentsPart, $this->contentsTemplate);
|
||||
}
|
||||
|
||||
public function setPlaceholder(string $placeholder, string $replacement): void
|
||||
{
|
||||
$this->mjml = str_replace($placeholder, $replacement, $this->mjml);
|
||||
}
|
||||
|
||||
public function send(): bool
|
||||
|
@ -62,6 +71,8 @@ class Email
|
|||
|
||||
$success = mail($to, $subject, $message, $headers);
|
||||
|
||||
error_log($html);
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,32 +69,18 @@ if (isset($_POST['reset'], $_POST['email'])) {
|
|||
;');
|
||||
|
||||
$emailReset = new Email($_POST['email'], __('Password reset link'), 'default', 'password-reset');
|
||||
$emailReset->mjml = str_replace(
|
||||
'TEXT_HELLO',
|
||||
__('Hello,'),
|
||||
$emailReset->mjml
|
||||
);
|
||||
$emailReset->mjml = str_replace(
|
||||
$emailReset->setPlaceholder('TEXT_HELLO', __('Hello,'));
|
||||
$emailReset->setPlaceholder(
|
||||
'TEXT_PASSWORD_RESET',
|
||||
__('somebody has requested a password reset for this email address from <a href="https://wishthis.online">wishthis.online</a>. If this was you, click the button below to invalidate your current password and set a new one.'),
|
||||
$emailReset->mjml
|
||||
__('somebody has requested a password reset for this email address from <a href="https://wishthis.online">wishthis.online</a>. If this was you, click the button below to invalidate your current password and set a new one.')
|
||||
);
|
||||
$emailReset->mjml = str_replace(
|
||||
'TEXT_SET_NEW_PASSWORD',
|
||||
__('Set new password'),
|
||||
$emailReset->mjml
|
||||
);
|
||||
$emailReset->mjml = str_replace(
|
||||
'wishthis.online',
|
||||
$_SERVER['HTTP_HOST'],
|
||||
$mjml
|
||||
);
|
||||
$emailReset->mjml = str_replace(
|
||||
$emailReset->setPlaceholder('TEXT_SET_NEW_PASSWORD', __('Set new password'));
|
||||
$emailReset->setPlaceholder('wishthis.online', $_SERVER['HTTP_HOST']);
|
||||
$emailReset->setPlaceholder(
|
||||
'password-reset-link',
|
||||
$_SERVER['REQUEST_SCHEME'] . '://' .
|
||||
$_SERVER['HTTP_HOST'] .
|
||||
Page::PAGE_REGISTER . '&password-reset=' . $_POST['email'] . '&token=' . $token,
|
||||
$mjml
|
||||
Page::PAGE_REGISTER . '&password-reset=' . $_POST['email'] . '&token=' . $token
|
||||
);
|
||||
|
||||
$emailReset->send();
|
||||
|
|
Loading…
Reference in a new issue