0

I'm trying to follow the instructions here: https://gist.github.com/butlerblog/7e4dbafcbc61b15505ee8ca90510f1e7

But I'm getting confused. I'm not sure what arguments to pass where. Here is what I have:

define( 'SMTP_USER',   '[email protected]' );    // The email address I use when I log in to the wp-admin page
define( 'SMTP_PASS',   '123password' );       // The password I use when I log in to the wp-admin page
define( 'SMTP_HOST',   'localhost' );    // I am testing this on localhost
define( 'SMTP_FROM',   '[email protected]' ); // Also the email address I use for logging in on the wp-admin page
define( 'SMTP_NAME',   'My Site 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',   1 );                    // for debugging purposes only set to 1 or 2

I am pretty sure I am not sending in the right stuff. When I try to use wp_mail, I get the following error in the debug log:

[0] => SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Any advice? Thank you!

4
  • So you set up a local smtp server to send it with? Because that's what your SMTP_HOST seems to suggest.
    – Hans
    Commented Oct 6, 2018 at 13:51
  • I am running my site on localhost for now. I thought this code was to set up the server. Can you explain?
    – ellen
    Commented Oct 7, 2018 at 21:08
  • 1
    You're not setting up a server with this code, you're essentially telling wp_mail to use a specific server for sending emails. If you define localhost as your SMTP_HOST, then you would need a running SMTP server on your local machine. Instead, you should probably get the SMTP credentials from your hosting provider, because you will most likely use their (remote) server for sending emails.
    – Hans
    Commented Oct 8, 2018 at 9:40
  • To build on @Michael's comment, SMTP_HOST must be an actual SMTP server you are connecting to. Your connection is failing because there is no SMTP server at localhost:25 (unless you've set up an actual email server to connect to, but based on your question and followup comment, that doesn't seem to be the case).
    – butlerblog
    Commented Nov 10, 2018 at 5:06

1 Answer 1

1

But based solely on what you posted, the problem is the following:

define( 'SMTP_USER',   '[email protected]' );    // The email address I use when I log in to the wp-admin page
define( 'SMTP_PASS',   '123password' );       // The password I use when I log in to the wp-admin page
define( 'SMTP_HOST',   'localhost' );    // I am testing this on localhost
define( 'SMTP_FROM',   '[email protected]' ); // Also the email address I use for logging in on the wp-admin page

The script you posted is to define the connection information to an SMTP server. Unless you are actually running an SMTP server on your localhost with the login credentials you supplied in the other constant definitions, then that is why your script is failing.

The SMTP_HOST constant must define the location of the SMTP email server you are trying to connect to (such as

Likewise, the login information should not be what you use to login to WordPress. You indicated in your comments that these are the login credentials that you use logging in to wp-admin. But what they should be is the login credentials for the email account on the SMTP server you are connecting to.

If you have an email account you are intend to send through, check with your email provider. They should be able to supply you with the correct connection information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.