Skip to content
Snippets Groups Projects
Commit 43426991 authored by Piotr Potrebka's avatar Piotr Potrebka
Browse files

feat: mail from

parent ca4eb5a7
No related branches found
No related tags found
1 merge request!2Devel
Pipeline #153494 passed
...@@ -75,24 +75,25 @@ class Mailer { ...@@ -75,24 +75,25 @@ class Mailer {
/** @return void */ /** @return void */
public function send() { public function send() {
foreach ( $this->get_emails() as $email ) { foreach ( $this->get_emails() as $email ) {
if ( $email->get_is_enable() ) {
add_filter( add_filter(
'wp_mail_from', 'wp_mail_from',
$from_cb = static function () use ( $email ) { $from_cb = static function ( $from ) use ( $email ) {
if ( ! empty( $email->get_from() ) ) { if ( ! empty( $email->get_from() ) ) {
return $email->get_from(); return $email->get_from();
} }
return 'wordpress@siteurl.pl'; return $from;
} }
); );
add_filter( add_filter(
'wp_mail_from_name', 'wp_mail_from_name',
$from_name_cb = static function () use ( $email ) { $from_name_cb = static function ( $from_name ) use ( $email ) {
if ( ! empty( $email->get_from_name() ) ) { if ( ! empty( $email->get_from_name() ) ) {
return $email->get_from_name(); return $email->get_from_name();
} }
return 'wordpress'; return $from_name;
} }
); );
add_action( 'wp_mail_failed', [ $this, 'catch_error' ] ); add_action( 'wp_mail_failed', [ $this, 'catch_error' ] );
...@@ -122,6 +123,8 @@ class Mailer { ...@@ -122,6 +123,8 @@ class Mailer {
} }
} }
}
/** @return void */ /** @return void */
public function catch_error( WP_Error $error ) { public function catch_error( WP_Error $error ) {
throw MailerException::with_wp_error( $error ); throw MailerException::with_wp_error( $error );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment