Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Testing the wp_mail Function – how to do that?

Discussion in 'Misc WordPress Requests' started by say_hello, Nov 3, 2017.

  1. say_hello

    Guest

    Reply To: Testing the wp_mail Function – how to do that?, by say_hello

    hello dear all – i want to share with you the steps:

    well with the check_mail plugin it does not work;

    well it seems that have issues with the mail in WP – it does not work
    to send mail with wp_mail does not run

    i have made some tests: they does not run

    what to do next

    love to hear from you

    i have runned the test: http://www.butlerblog.com/2012/09/23/testing-the-wp_mail-function/


    Focus on the first three required arguments. If email sends with those then wp_mail is functioning. If not, further testing may require looking into the $headers. Some hosts require that valid “from” headers be used, so that is something that should be checked.
    Simple wp_mail Testing Snippet
    The following script that allows you to test WordPress email by attempting to send an email through your site. To use this testing script, save it as a php file and load it to your WP root directory via FTP.
    Set your email address as indicated in the example script. Save the file as mailtest.php, then browse to it directly in your browser to fire the wp_mail function (http://yourdomain.com/mailtest.php). You will get a result on screen, and if all is functioning, you will receive a test message in your inbox. If you get an error message or you don’t receive the email, there is an issue with wp_mail.
    Here is the script. I plan to put this together in a utility plugin at some point in the future, but for now, you can save it as a php file and run it from your WP root folder.

    <?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 = "[email protected]";

    // 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!';

    }


    well this did not work:

    i have found another idea – the easy-smtp-email-wordpress-wp_mail

    http://www.butlerblog.com/2013/12/12/easy-smtp-email-wordpress-wp_mail/

    Dealing with getting WordPress to properly send emails can be a source of frustration for even a seasoned developer. Relying on the web server to send email (which is what WordPress’ wp_mail() function does by default) is unreliable.
    Here’s a simple method to change that – without needing a plugin. In fact, this will be more secure than a plugin. A plugin is a simple solution, and there are some good ones out there. But this method will give you the same benefit in a smooth and secure configuration.

    In fact, I’ve changed the recommended process from what I originally wrote for this article. Originally, the entire process was in a single code snippet. But I’ve had a number of more advanced users complain about security with that – and they are correct. Originally, I had focused on providing something more robust for the novice user and wanted to keep it simple. The fact is for the average novice, that would have been fine. But why not teach it better from the beginning?
    So now the process is two code snippets. The first is adding your credentials and setting to your wp_config.php file. This keeps it away from prying eyes that might have access to your admin panel, but not your file system.

    The main code snippet then uses the constants you define in the wp_config.php file.

    Setting it up
    Setting up WordPress to use SMTP for sending email is extremely simple. You don’t really need any different information than you would for email plugin settings. All you need is your login credentials, the account information, server location and you can do this all with a few lines of simple code.

    Sound good? Great – let’s get started.
    WordPress’s email function wp_mail is essentially a wrapper for phpmailer, a popular email class for PHP. WordPress has a little known action hook when phpmailer is initialized, phpmailer_init. This allows you to establish the phpmailer instance as using SMTP.

    The config file
    First, in your wp_config.php file, add constants for your SMTP server information. Add this somewhere in wp_config.php BEFORE the constant ABSPATH is defined. A good place is immediately before the line that has a comment saying “That’s all, stop editing! Happy blogging.”

    <?php
    /**
    * Set the following constants in wp-config.php
    * These should be added somewhere BEFORE the
    * constant ABSPATH is defined.
    */
    define( 'SMTP_USER', '[email protected]' ); // Username to use for SMTP authentication
    define( 'SMTP_PASS', 'smtp password' ); // Password to use for SMTP authentication
    define( 'SMTP_HOST', 'smtp.example.com' ); // The hostname of the mail server
    define( 'SMTP_FROM', '[email protected]' ); // SMTP From email address
    define( 'SMTP_NAME', 'e.g Website Name' ); // SMTP From name
    define( 'SMTP_PORT', '25' ); // SMTP port number - likely to be 25, 465 or 587
    define( 'SMTP_SECURE', 'tls' ); // Encryption system to use - ssl or tls
    define( 'SMTP_AUTH', true ); // Use SMTP authentication (true|false)
    define( 'SMTP_DEBUG', 0 ); // for debugging purposes only set to 1 or 2



    This is defining your SMTP server information for phpmailer as constants that can be used later, anywhere in your WP installation. Keep in mind that depending on your specific mail server settings and requirements you may need to change the values in the example. I’ve included comments to tell you what each value is.
    The phpmailer action for wp_mail

    Now that the constants are defined, we can set up wp_mail() to use them. This code snippet will use the SMTP constants you defined to have wp_mail() send using your SMTP server instead of your web server’s email server. You can add this to your theme’s functions.php file or build a custom plugin file to contain it. The advantage of a custom plugin file is that it’s theme independent.

    <?php
    /**
    * This function will connect wp_mail to your authenticated
    * SMTP server. This improves reliability of wp_mail, and
    * avoids many potential problems.
    *
    * Values are constants set in wp-config.php
    */
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host = SMTP_HOST;
    $phpmailer->SMTPAuth = SMTP_AUTH;
    $phpmailer->Port = SMTP_PORT;
    $phpmailer->Username = SMTP_USER;
    $phpmailer->Password = SMTP_PASS;
    $phpmailer->SMTPSecure = SMTP_SECURE;
    $phpmailer->From = SMTP_FROM;
    $phpmailer->FromName = SMTP_NAME;
    }


    functions.php

    Troubleshooting and more information

    To use this, you will need to adjust the settings according to your email service requirements. Check with your host to make sure you know the proper port to use as well as the encryption method.

    For more information on testing, troubleshooting, and changing your WordPress email configuration for wp_mail, here are some additional posts:
    Testing your WordPress email settings for the wp_mail function – some information on wp_mail and a testing script you can use to make sure it is sending messages.
    Troubleshooting wp_mail WordPress Email Configuration – not everything that can go wrong is directly a problem with WP. This post has information on host restrictions and other outside problems that should be checked.
    WordPress Email Settings: Changing the wp_mail address with a simple plugin – here is a very simple and lightweight script you can load as a plugin to change the email address that WordPress sends email from.
    Changing the wp_mail from address in WordPress without a plugin – provides a simple code snippet you can use to change the email address that WordPress sends from, no plugin required.

    http://www.butlerblog.com/2013/12/12/easy-smtp-email-wordpress-wp_mail/

    i will do further tests now. …i want to share with you all the steps!!

    Reply To: Testing the wp_mail Function – how to do that?
     
    #1

Share This Page

Web Hosting