• zaydB

    (@zaydb)


    Hey guys,

    I run several websites on one server and for some reason I cant seem to use wp_mail to send emails through my main domain. Every other domain and new domains I create work but not the main domain. Ive tried using several plugins including wp-mail-smtp but unfortunately I cant get my main domain to send mail using the wp_mail function. I can use the mail() function but this isnt ideal and I heard it can be easily hacked. I wrote a script to test the wp_mail function:

    <?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.
     */
    
    // Set $to as the email you want to send the test to
    $to = "support@XXXXX.com.au";
    
    // 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 = 'no-reply@xxxx.com.au';
    
    // 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!';
    }

    This function seems to work with my sub-domains but not with my main domain. The error message just says message not sent. Is there a way I can test wp_mail better? Maybe get a more meaningful error message that can help me pin-point the problem code? My hosting provider insist its a wordpress issue.

    Kind Regards

    UPDATE:
    So i’ve reinstalled my core wordpress files and the problem is still there.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Bob Cristello

    (@gntmidnight)

    If you are running this as a stand-along php page there is no way the wp_mail function will work because you haven’t loaded WordPress. You may want to take a look at this page:

    https://wordpress.org/support/topic/integrating-wp-in-external-php-pages?replies=22

    You may want to use php mail in order to accomplish what you want:

    http://php.net/manual/en/function.mail.php

    Thread Starter zaydB

    (@zaydb)

    Hey mate,
    Thanks for the reply but this script works on my sub-domains, I’m not running it as a stand-alone wordpress page. It run within a directory that has all the wordpress core files and directories. So as that forum that you pointed to me suggested ‘within the wordpress folder with wp-admin folder’. I cant use the php mail function because it has been disabled by my host when someone tries to access it implicitly. Its also not a very secure way of sending mail and can cause spam issues. What im really looking for is a better way to test wp-mail, so a script that can tell me exactly why the email wasnt sent and not just a simple ‘message not sent’ text.
    Again thanks for your help

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sending mail through a plugin using wp_mail’ is closed to new replies.