https://github.com/rdelbem/wp-mailer-class
https://github.com/rdelbem/wp-mailer-class
email mail wordpress
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rdelbem/wp-mailer-class
- Owner: rdelbem
- Created: 2021-07-14T18:51:21.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-19T01:23:00.000Z (about 3 years ago)
- Last Synced: 2025-07-28T08:50:37.833Z (11 months ago)
- Topics: email, mail, wordpress
- Language: PHP
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Simple WordPress Mailer class
The intention of this snippet is to facilitate the use of wp_mail native function.
Normally, when using, wp_mail, some parameters are required in order for it to work: headers, subject, body etc.
If all you have is the user id, you will need to use other WordPress function to get the email and, only then, pass it to wp_mail. While, coding a plugin or a theme, this will require a different file and class, as calling all this wp functions will, most certanly, make a mess in your code.
However, if you use WPMailerClass, you only need to provide ONE relevant receiver data, id OR email. See the examples:
Here, only id is provided
```php
$send_mail = new WPMailerClass( 1, 'Amazing subject!', 'Amazing message!' );
$send_mail->sendEmail();
```
Here, only e-mail is provided
```php
$send_mail = new WPMailerClass( 'youruser@mail.com', 'Amazing subject!', 'Amazing message!' );
$send_mail->sendEmail();
```
And if you want to defensive handle errors you can do the following
```php
$send_mail = new WPMailerClass( 'youruser@mail.com', 'Amazing subject!', 'Amazing message!' );
$result = $send_mail->sendEmail();
if($result instanceof WP_Error){
error_log($result->get_error_message()); // this will log 'WPMailerClass could not send email'
}
```