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 */
|
/** Send email */
|
||||||
$user = new User($wishlist['user']);
|
$user = new User($wishlist['user']);
|
||||||
$email = new Email($user->email, __('Wish request'), 'default', 'wishlist-request-wishes');
|
$email = new Email($user->email, __('Wish request'), 'default', 'wishlist-request-wishes');
|
||||||
$email->mjml = str_replace(
|
$email->setPlaceholder('TEXT_HELLO', __('Hello,'));
|
||||||
'TEXT_HELLO',
|
$email->setPlaceholder(
|
||||||
__('Hello,'),
|
|
||||||
$email->mjml
|
|
||||||
);
|
|
||||||
$email->mjml = str_replace(
|
|
||||||
'TEXT_WISHLIST_REQUEST_WISHES',
|
'TEXT_WISHLIST_REQUEST_WISHES',
|
||||||
sprintf(
|
sprintf(
|
||||||
/** TRANSLATORS: %s: Wishlist name */
|
/** TRANSLATORS: %s: Wishlist name */
|
||||||
__('somebody has requested that you add more wishes to your wishlist %s.'),
|
__('somebody has requested that you add more wishes to your wishlist %s.'),
|
||||||
'<a href="' . $href . '">' . $wishlist['name'] . '</a>'
|
'<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();
|
$success = $email->send();
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,9 @@ use Qferrer\Mjml\Renderer\ApiRenderer;
|
||||||
|
|
||||||
class Email
|
class Email
|
||||||
{
|
{
|
||||||
public string $mjml;
|
private string $mjml = '';
|
||||||
|
private string $contentsTemplate;
|
||||||
|
private string $contentsPart;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private string $to,
|
private string $to,
|
||||||
|
@ -24,8 +26,15 @@ class Email
|
||||||
private string $template,
|
private string $template,
|
||||||
private string $part
|
private string $part
|
||||||
) {
|
) {
|
||||||
$this->mjml = file_get_contents(ROOT . '/src/mjml/' . $this->template . '.mjml');
|
$this->contentsTemplate = file_get_contents(ROOT . '/src/mjml/' . $this->template . '.mjml');
|
||||||
$this->mjml = str_replace('MJML_PART', 'parts/' . $this->part . '.mjml', $this->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
|
public function send(): bool
|
||||||
|
@ -62,6 +71,8 @@ class Email
|
||||||
|
|
||||||
$success = mail($to, $subject, $message, $headers);
|
$success = mail($to, $subject, $message, $headers);
|
||||||
|
|
||||||
|
error_log($html);
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,32 +69,18 @@ if (isset($_POST['reset'], $_POST['email'])) {
|
||||||
;');
|
;');
|
||||||
|
|
||||||
$emailReset = new Email($_POST['email'], __('Password reset link'), 'default', 'password-reset');
|
$emailReset = new Email($_POST['email'], __('Password reset link'), 'default', 'password-reset');
|
||||||
$emailReset->mjml = str_replace(
|
$emailReset->setPlaceholder('TEXT_HELLO', __('Hello,'));
|
||||||
'TEXT_HELLO',
|
$emailReset->setPlaceholder(
|
||||||
__('Hello,'),
|
|
||||||
$emailReset->mjml
|
|
||||||
);
|
|
||||||
$emailReset->mjml = str_replace(
|
|
||||||
'TEXT_PASSWORD_RESET',
|
'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.'),
|
__('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
|
|
||||||
);
|
);
|
||||||
$emailReset->mjml = str_replace(
|
$emailReset->setPlaceholder('TEXT_SET_NEW_PASSWORD', __('Set new password'));
|
||||||
'TEXT_SET_NEW_PASSWORD',
|
$emailReset->setPlaceholder('wishthis.online', $_SERVER['HTTP_HOST']);
|
||||||
__('Set new password'),
|
$emailReset->setPlaceholder(
|
||||||
$emailReset->mjml
|
|
||||||
);
|
|
||||||
$emailReset->mjml = str_replace(
|
|
||||||
'wishthis.online',
|
|
||||||
$_SERVER['HTTP_HOST'],
|
|
||||||
$mjml
|
|
||||||
);
|
|
||||||
$emailReset->mjml = str_replace(
|
|
||||||
'password-reset-link',
|
'password-reset-link',
|
||||||
$_SERVER['REQUEST_SCHEME'] . '://' .
|
$_SERVER['REQUEST_SCHEME'] . '://' .
|
||||||
$_SERVER['HTTP_HOST'] .
|
$_SERVER['HTTP_HOST'] .
|
||||||
Page::PAGE_REGISTER . '&password-reset=' . $_POST['email'] . '&token=' . $token,
|
Page::PAGE_REGISTER . '&password-reset=' . $_POST['email'] . '&token=' . $token
|
||||||
$mjml
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$emailReset->send();
|
$emailReset->send();
|
||||||
|
|
Loading…
Reference in a new issue