Can't send email in PHP using Postfix

I already installed Postfix and it’s working sending from terminal. But Send mail via PHP is not coz I do know what setting or how to create or get the usersname / password and other details needed


define(‘MAILER’, “smtp”);

define(‘SMTP_HOST’, “”);

define(‘SMTP_PORT’, 587);

define(‘SMTP_USERNAME’, “”);

define(‘SMTP_PASSWORD’, “”);

define(‘SMTP_ENCRYPTION’, “”);

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Wordpress uses PHP mail() by default. If you disable/uninstall any extensions that try to manage email sending and delete the configuration lines above from wp-config.php, it should work fine.

You can check if PHP’s mail() function is working properly by creating a file with the following content:

    ini_set('display_errors', 1);
    mail ('', 'Postfix Test', 'A test email') || print_r(error_get_last());

Place it in your document root (e.g. /var/www/html) and browse to it. If it’s blank, everything went well and you should receive an email shortly.

PHP uses an MTA to send it’s mails trough mail(), if you want to override it on system level you could edit /etc/postfix/ and add

relayhost = [smtp.domain.tld]:587

if you are on an older system, you might need to configure sendmail instead