1. Go to this page and download the library: Download rumur/wp-mailer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rumur / wp-mailer example snippets
use Rumur\WordPress\Mailer\Mailer;
// This will change it for all emails that being sent via that mailer.
Mailer::useAlwaysFromEmail('[email protected]');
Mailer::useAlwaysFromName('More then a blog.');
// However it can be changed per email only.
Mailer::make(wp_get_current_user(), 'My Blog.', '[email protected]')->send($mailable);
namespace App\Emails;
use Rumur\WordPress\Mailer\Mailable;
use Rumur\WordPress\Mailer\WordPressMailParams;
final class Invoice extends Mailable
{
/**
* @var \Order
*/
protected $order;
/**
* Invoice constructor.
* @param \Order $order
*/
public function __construct(\Order $order)
{
$this->order = $order;
}
/**
* Builds an email params.
*
* @return WordPressMailParams
*/
public function build(): WordPressMailParams
{
// Takes Attached files from the order and converts into relative file paths
$as_files = array_map(static function ($file) {
return get_attached_file($file);
}, $this->order->file_ids);
$this->setAttachments($as_files);
// Also could be attached as id or an array of ids, will transform them to files.
$this->addAttachment($this->order->file_ids);
// Also could be mixed
$this->addAttachment([
$file_id = 2020,
$file_path = WP_CONTENT_DIR . '/uploads/2020/05/lorem.png',
]);
// ⚠️ OPTIONAL ⚠️
// The subject could be explicitly set or the Email class name will be taken as a subject.
$this->subject(
sprintf(_x('Invoice Number %d', 'Invoice Subject', 'text-domain'), $this->order->id)
);
return parent::build();
}
/**
* The Main message of an Email.
* @return string
*/
public function body(): string
{
// TODO: Implement body() method.
}
}
use Rumur\WordPress\Mailer\Mailer;
use Rumur\WordPress\Mailer\Dispatcher;
use Rumur\WordPress\Mailer\WordPressMailParams;
$order = OrderRepository::find(214);
Mailer::instance()
// ⚠️ OPTIONAL ⚠️
// These local options will be used instead of always ones.
->from('Custom From Name', '[email protected]')
// If `to` gets a \WP_User instance,
// it also will set the locale from user's data.
// You also allowed to pass a regular valid email as well.
->to(wp_get_current_user())
// ⚠️ OPTIONAL ⚠️
// Sets the Carbon Copy of the email.
->cc(['[email protected]', get_user_by('id', 2222)])
// ⚠️ OPTIONAL ⚠️
// Sets the Blind Carbon Copy of the email.
->bcc('[email protected]')
// ⚠️ OPTIONAL ⚠️
// Use the `locale` method in order to explicitly set the locale of the email,
// otherwise the locale will be taken from a user if a WP_USer has been passed via a `to` method
// ⚠️ Note once the email has been dispatched the main blog locale will be restored back
->locale('en_US')
// ⚠️ OPTIONAL ⚠️
// This listener will be triggered in case of the mailer encountered with an error
->onFailure(static function (\WP_Error $error, WordPressMailParams $params, Dispatcher $dispatcher) {
// Do something with that error.
})
// ⚠️ OPTIONAL ⚠️
->onSuccess(static function (WordPressMailParams $params, Dispatcher $dispatcher) {
// Do something with that information.
})
// ⚠️ OPTIONAL ⚠️
// The Email could be sent when a WordPress action has been fired.
->sendOnAction('user_payment_completed', new App\Emails\Invoice($order))
// ⚠️ OPTIONAL ⚠️
// The Email could be sent when the condition is `true`.
->sendWhen($order->isPayed(), new App\Emails\Invoice($order))
// ⚠️ OPTIONAL ⚠️
// This method
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.