Articles of wp mail

Email all subscribers when i do an action

I’ve created this function: function email_subscribed_users($event) { $users = get_users(‘role=subscriber’); foreach ($users as $user) { $accepted = get_user_meta($user->ID, ‘accepted’, true); if ($accepted) { wp_mail($recipients, $event->event_title, $event->event_desc, ‘From: <>’); } } } But it requires a lot of time sending the emails knowing that the users will increase by time.What function should I use to send […]

On user registration, if welcome mail sent, add post with new user as author

I am trying to create a new post (later will convert it into custom post type), whenever a new user register on the website and if the welcome email was sent succesfully. The problem is that I want to add the new user as the author of the new post. Later all notification emails will […]

How to create a CSV on the fly and send as an attachment using wp_mail?

I’m trying to create a CSV file from a form submission and send that file automatically by email to a specific user. The email itself is sending fine, but I can’t get the attachment to go through. Is it possible to create an attachment without first saving the file to the server? function create_csv() { […]

Intercepting WP_MAIL to view contents

I’m looking for a way to hook into the mail function before it sends so I can var_dump the output. Are there any action hooks with the mail message that I can hook into? I’m having trouble finding the wp_mail function in core. Any other methods of debugging mail output would be greatly appreciated as […]

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

Is there a conditional check I can run for phpmailer_init or a wp_mail parameter that let’s me apply my custom phpmailer_init SMTP settings only on specific wp_mail actions or does phpmailer_init always run sitewide?

Adding second Email address for WP user notifications

The WP systems sends a lot of mails to authors. There also plugins who use email notifications for authors. But, let say I have a user, who is managed by two persons (because it’s a company, an entity that is more then one person) – I want all the emails to be sent also to […]

Need clarification on how to correctly call wp_mail()

I want to call wp_mail() from a non-template php file, but when I do so it fails and I don’t understand why. For example, let’s say I have a php file that consists of only this: <?php echo ‘hi’; $mail_sent = wp_mail(‘’, ‘subject’, ‘message’); echo $mail_sent; ?> If I load that php file directly in […]

WordPress wp_mail() how to add a .GIF

I’m using wp_mail() to send e-mail from our website. However, we would like to include a .gif file on the body of our message. Here’s my code, but it’s not working. $to = $contact[‘Email’]; $from = ‘’; // To send HTML mail, the Content-type header must be set $headers = ‘MIME-Version: 1.0’ . “\r\n”; $headers […]

Different Webhost and using Google Mail server: Is there a better way than SMTP?

Currently my situation is the following: I am using WordPress which handles a few things mail related: Registration forms that send a notification and contact form that send a message. However, because the mail server we use it a remote mail server connected to with SMTP, the contact form is confusing. The email that is […]

Email 'from address' has a www in it

When sending emails from my WordPress install, my ‘from address’ includes a www. Currently, it’s sending email from when what I want is However, if I change the domain name – lets say to – it works properly. I tried to add some code to my theme’s functions.php to force a rewrite […]