How to test your wordpress wp_mail function

How to test your wordpress wp_mail function

As a startup website owner, you will need to ensure the web registration process of your startup website is working perfectly.

When you use Wordpress as your Content Management System (CMS), then the default function to send email from a webserver is wp_mail function.

If you have problem not receiving the email for example when you are using WP-Members plugin.

First step is to test if your wp_mail is working or not, since the WP-Members is using wp_mail to send the email during registration or reset the member password.

You can copy these lines, and save it as mailtest.php, and upload to the root directory of your wordpress.

You will need to change this $to = "yourname@yourdomain.com"; to your real email destination.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
 * This file can be used to validate that the WordPress wp_mail() function is working.
 * To use, change the email address in $to below, save, and upload to your WP root.
 * Then browse to the file in your browser.
 * 
 * For full discussion and instructions, see the associated post here:
 * http://b.utler.co/9L
 * 
 * Author:      Chad Butler
 * Author URI:  http://butlerblog.com/
 */
/*  
 Copyright (c) 2012-2015  Chad Butler
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License, version 2, as
 published by the Free Software Foundation.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 You may also view the license here:
 http://www.gnu.org/licenses/gpl.html
*/
 
// Set $to as the email you want to send the test to.
$to = "yourname@yourdomain.com";
 
// No need to make changes below this line.
 
// Email subject and body text.
$subject = 'wp_mail function test';
$message = 'This is a test of the wp_mail function: wp_mail is working';
$headers = '';
 
// Load WP components, no themes.
define('WP_USE_THEMES', false);
require('wp-load.php');
 
// send test message using wp_mail function.
$sent_message = wp_mail( $to, $subject, $message, $headers );
//display message based on the result.
if ( $sent_message ) {
    // The message was sent.
    echo 'The test message was sent. Check your email inbox.';
} else {
    // The message was not sent.
    echo 'The message was not sent!';
}

If the message was sent, it shows that you have no problem with your wp_mail function, and you should investigate in another section.




Popular Posts