Ready to get started?Download WordPress


Plugin API/Action Reference/phpmailer init

This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.



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.


(array) (required) An array of arguments
Default: None


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

add_action( 'phpmailer_init', 'my_phpmailer_example' );
function my_phpmailer_example( $phpmailer ) {
    $phpmailer->Host = 'smtp.example.com';
    $phpmailer->Port = 25;
    $phpmailer->Username = 'yourusername';
    $phpmailer->Password = 'yourpassword';


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.

Change Log

Since: Version 2.2

Source Files

phpmailer_init is located in wp-includes/pluggable.php