<?php // Don't use this line. | |
/* | |
* Add the script below to wherever you store custom code snippets | |
* in your site, whether that's your child theme's functions.php, | |
* a custom plugin file, or through a code snippet plugin. | |
*/ | |
/** | |
* This function will connect wp_mail to your authenticated | |
* SMTP server. This improves reliability of wp_mail, and | |
* avoids many potential problems. | |
* | |
* For instructions on the use of this script, see: | |
* https://butlerblog.com/easy-smtp-email-wordpress-wp_mail/ | |
* | |
* Values for constants are 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; | |
} |
<?php // Don't use this line. | |
/** | |
* Set the following constants in wp-config.php | |
* These should be added somewhere BEFORE the | |
* constant ABSPATH is defined. | |
* | |
* Make sure you know from your email host what your specific connection | |
* parameters are. Common defaults are given below, but if they are not | |
* what your host requires, you won't be able to connect. Each constant | |
* is noted with a comment identifying what connection parameter it is, | |
* but make sure you're using the correct value - check with your | |
* email host to confirm specific requirements. (Also confirm that your | |
* host allows remote connections in the first place.) | |
* | |
* For instructions on the use of this script, see: | |
* https://butlerblog.com/easy-smtp-email-wordpress-wp_mail/ | |
*/ | |
define( 'SMTP_USER', 'user@example.com' ); // 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', 'website@example.com' ); // 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 comment has been minimized.
This comment has been minimized.
Sometimes works? what that does mean?? how can I say to my client: Sometimes the web will send emails?... SOMETIMES!!! |
This comment has been minimized.
This comment has been minimized.
The code works! What must the extension be if I want to use a reply address "addReplyTo"? |
This comment has been minimized.
This comment has been minimized.
confirmed, this sometimes works. |
This comment has been minimized.
This comment has been minimized.
This code DOESN'T work! |
This comment has been minimized.
This comment has been minimized.
For the people that have commented that this "works sometimes" or that it doesn't work at all... if your site's email is not working, the problem is not the code snippet. Implementing this is actually quite simple and requires little to no testing IF you actually know the requirements of your email server. So asking your email provider ahead of time for information will save you a lot of headache. First, make sure you know the issue isn't somewhere upstream. Is the process by which Next, have you implemented this code correctly? Placement is critical as is understanding "order of operations" in WordPress. If those things don't make sense, you need to make sure you following the listed instructions carefully. Defining the constants MUST go in wp-config.php BEFORE If you know for certain that email is being generated and handed off to the next step, then check the following, some of which requires asking your email service provider what the required settings are for a remote connection (i.e. if you're "guessing" at the values without knowing for certain, then you're just going to beat your head against the wall).
Not every mail server is configured the same way. If you're beating your head against the wall to make email work, start by checking with your host's support to find out if you're even using the right parameters for your connection script. And instead of simply copy/pasting code you don't understand, try reading the instructions provided and make sure you know how to determine if the issue is upstream or downstream and where you should be looking for the solution. |
This comment has been minimized.
This comment has been minimized.
This will work sometimes, and sometimes will not - confirmed |
This comment has been minimized.
This comment has been minimized.
but again I strongly agree with all what you said @butlerblog in previous long comment .. so this is something that I have to debug for my client now - to see where it leaks |
This comment has been minimized.
This code sometime works