Skip to main content
Share Your Experience: Take the 2024 Developer Survey
17 votes

Check to check if wp_mail is working properly?

You can use the 'wp_mail_failed' action to catch a send error. https://developer.wordpress.org/reference/hooks/wp_mail_failed/
gbones's user avatar
  • 291
17 votes

Multiple email recipient using wp_mail()

Yes it's possible, $to accepts an array or comma-separated list of email addresses to send message. You can read more here, about optional headers parameter that can add from, cc, content-type, ...
Benoti's user avatar
  • 2,436
13 votes

Include HTML template file in wp_mail

Here is the sample code for using output buffering. You will be able to access all the variables inside the template which are defined above "include line". WordPress: Include template in the email....
Mayur Chauhan's user avatar
11 votes

Sending multipart (text/html) emails via wp_mail() will likely get your domain banned

TLDR, the simple solution is: add_action('phpmailer_init','wp_mail_set_text_body'); function wp_mail_set_text_body($phpmailer) { if (empty($phpmailer->AltBody)) {$phpmailer->AltBody = ...
majick's user avatar
  • 5,081
10 votes

Unable to prevent function using save_post firing twice

The approved answer didn't work for me. I ended up trying several conditionals and the email would still get sent twice: function xxx_send_mail($id, $post, $update){ if (defined('...
Uriahs Victor's user avatar
9 votes

How to set SMTP programmatically

The other answers to this post, while providing a working solution, don't address the security issue of storing your SMTP credentials in a plugin file or functions.php. In some cases that may be OK, ...
butlerblog's user avatar
  • 4,996
9 votes

How to apply the "retrieve_password_message" filter?

the given answers have good intentions. But are not good. There are more parameters to the filter function call, 4 to be exact. this worked for me for the message (i wanted to replace username with ...
Toskan's user avatar
  • 524
8 votes

how to set from address according to the form input email address for wp_mail()?

For this filtering the email address: add_filter( 'wp_mail_from_name', 'my_mail_from_name' ); function my_mail_from_name( $name ) { return "My Name"; } Now add a filter for the name of the email ...
Yogesh Shakya's user avatar
7 votes
Accepted

How to add headers to outgoing email?

Thanks to the above, I've realized my central mistake -- I didn't quite realize that the arguments being passed in were a multi-dimensional array. For now, I've re-implemented the function thus: ...
David E. Smith's user avatar
7 votes

Should I use wp_mail or PHP's mail?

WordPress offers its own mailing system. I suggest you use that instead of PHP's native mail. wp_mail accepts five arguments: wp_mail( $to, $subject, $message, $headers, $attachments ); So your ...
Johansson's user avatar
  • 15.3k
6 votes

How to add headers to outgoing email?

Here's an alternative using directly the AddCustomHeader method of the PHPMailer instance: /** * Add a custom header. * $name value can be overloaded to contain * both header name and value (name:...
birgire's user avatar
  • 67.4k
6 votes

wp_mail() is not working in localhost

If anybody stumbles across this old question: In my case, the reason was, I gave the site at localhost a name without a top-level domain. e.g. "mysite" (instead of "mysite.com"). ...
Ronni's user avatar
  • 61
6 votes
Accepted

Email reply to multiple email addresses not working

Unfortunately this is not widely supported, not because WordPress does not support it, but because most email clients do not support it, so it cannot be relied upon. Instead, consider using a mailing ...
Tom J Nowell's user avatar
  • 59.5k
5 votes
Accepted

How to use 'phpmailer_init' SMTP settings only on certain 'wp_mail' actions?

phpmailer_init will always fire for every wp_mail() call - however, you can hook/unhook it conditionally like so: function wpse_224496_phpmailer_init( $phpmailer ) { // SMTP setup // Always ...
TheDeadMedic's user avatar
  • 36.4k
5 votes

Sending multipart (text/html) emails via wp_mail() will likely get your domain banned

For anyone that's using the phpmailer_init hook to add their own 'AltBody': The alternative text body is reused for different consecutive mails being sent, unless you clear it manually! WordPress ...
Tanuki's user avatar
  • 53
5 votes
Accepted

Unable to prevent function using save_post firing twice

First, you can use this hook to target only one custom type: https://developer.wordpress.org/reference/hooks/save_post_post-post_type/ This hook (and save_post) is called the first time when you ...
mmm's user avatar
  • 3,704
5 votes

Unable to prevent function using save_post firing twice

Already approved answers have not worked for me and comment from @Nico Pernice helped. If conditions in my code look like these: function reset_cpt_expire( $post_id, $post, $update ){ // Check if ...
Saqib's user avatar
  • 53
5 votes
Accepted

Warning: include(): https:// wrapper is disabled in the server configuration by allow_url_include=0

replace the first line on this include(get_template_directory() . '/inc/email_templates/quote.php'); when accessing a file, use the absolute path, not the uri
ktscript's user avatar
  • 254
4 votes

Sending HTML email with attachment with wp_mail()

Reference link click here. Using below code you can send the mail with html format. $to = '[email protected]'; $subject = 'The subject'; $body = 'The email body content'; $headers = array('Content-...
Naveen Kumar's user avatar
4 votes

Email 'from address' has a www in it

You can change the email address with the wp_mail_from filter: add_filter( 'wp_mail_from', function() { return '[email protected]'; } );
Morgan Estes's user avatar
  • 1,525
4 votes
Accepted

Intercepting wp_mail() to view contents

The first link on Google is to https://developer.wordpress.org/reference/functions/wp_mail/ which says that wp_mail is in wp-includes/pluggable.php It also has the full function source code showing ...
Andy Macaulay-Brook's user avatar
4 votes
Accepted

wp_mail not sending in test php file

Your test.php file is a standalone script and isn't part f WordPress so it has no access to the WordPress functions. A simple way to resolve this would be to include wp-load.php at the top of your ...
Tunji's user avatar
  • 2,931
4 votes
Accepted

WordPress is executing URL in code when called via wp_mail()

Please try the following, I think having a return from the site_url() function could be creating a problem with the $confirm_url variable. That and you have an unescaped slash in your url. $site_url ...
admcfajn's user avatar
  • 1,316
4 votes

How to setup SMTP for only one specific wp_mail()

The following is a way to handle your question. It is in two parts. First, you would create your connection as constants to be used later. The best way to do this is in wp-config.php. (You ...
butlerblog's user avatar
  • 4,996
4 votes

How to use PHPmailer in a function in WordPress

require 'wp-includes/class-phpmailer.php'; fixed my problem, but I used a code to create a pdf and then send it in the same way.
izaak's user avatar
  • 41
4 votes
Accepted

WordPress "phpmailer_init" not working for me

Where is the problem? Am I doing something wrong? Your code seems fine to me, so despite I can't give you a definitive answer on what/where exactly is the problem, I thought these might help you ...
Sally CJ's user avatar
  • 39.3k
3 votes

How to add headers to outgoing email?

PHP headers are strings. You can not parse them as array. You need to add you additional header as string with \r\n to make sure it is added in next line. Example: add_filter('wp_mail', '...
Sumit's user avatar
  • 4,804
3 votes

Sending multipart (text/html) emails via wp_mail() will likely get your domain banned

My simply solution is to use html2text https://github.com/soundasleep/html2text in this way: add_action( 'phpmailer_init', 'phpmailer_init' ); //http://wordpress.stackexchange.com/a/191974 //http://...
Frugan's user avatar
  • 131
3 votes

How to stop the wp_mail function?

//dont work for me: $phpmailer = new stdClass; //for stop wp_mail function use: function my_action( $phpmailer ) { if( condition ) { $phpmailer->ClearAllRecipients(); } } ...
Jérome Obbiet's user avatar
3 votes

How do I call wp_mail from HTML?

First the way to do this is with a form using the post method, it is slightly easier to understand: <!-- form with AJAX action and iframe target --> <form method="post" action="<?php echo ...
majick's user avatar
  • 5,081

Only top scored, non community-wiki answers of a minimum length are eligible