do_action_ref_array( 'phpmailer_init', PHPMailer $phpmailer )

Fires after PHPMailer is initialized.


Parameters Parameters

$phpmailer

(PHPMailer) The PHPMailer instance (passed by reference).


Top ↑

More Information More Information

The wp_mail() function relies on the PHPMailer class to send email through PHP’s mail function. The phpmailer_init action hook allows you to hook to the phpmailer object and pass in your own arguments.

This action is initiated with `do_action_ref_array` rather than `do_action`. You still hook to it with `do_action`. However, there are some notable differences:

  • If you pass an array to `do_action_ref_array()`, each element’s value of that array is passed as a separate parameter to the callback.
  • If you pass an array to `do_action()`, the complete array is passed as a single argument including any keys.

Top ↑

Source Source

File: wp-includes/pluggable.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
2.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by stevenlinx

    Example migrated from Codex:

    This is an example of establishing an SMTP connection using the `phpmailer_init` action:

    function my_phpmailer_example( $phpmailer ) {
        $phpmailer->isSMTP();     
        $phpmailer->Host = 'smtp.example.com';
        $phpmailer->SMTPAuth = true; // Ask it to use authenticate using the Username and Password properties
        $phpmailer->Port = 25;
        $phpmailer->Username = 'yourusername';
        $phpmailer->Password = 'yourpassword';
    
        // Additional settingsā€¦
        //$phpmailer->SMTPSecure = 'tls'; // Choose 'ssl' for SMTPS on port 465, or 'tls' for SMTP+STARTTLS on port 25 or 587
        //$phpmailer->From = "you@yourdomail.com";
        //$phpmailer->FromName = "Your Name";
    }
    add_action( 'phpmailer_init', 'my_phpmailer_example' );
    

You must log in before being able to contribute a note or feedback.