Report this

What is the reason for this report?

Can't send email in PHP using Postfix

Posted on October 25, 2015

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

//EMAIL SENDING CONFIGURATION

define(‘MAILER’, “smtp”);

define(‘SMTP_HOST’, “”);

define(‘SMTP_PORT’, 587);

define(‘SMTP_USERNAME’, “”);

define(‘SMTP_PASSWORD’, “”);

define(‘SMTP_ENCRYPTION’, “”);



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!

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.

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:

<?php
    ini_set('display_errors', 1);
    error_reporting(-1);
    mail ('you@example.com', '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/main.cf and add

relayhost = [smtp.domain.tld]:587

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.