Can't send email in PHP using Postfix

Posted October 25, 2015 31.5k views

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’, “”);

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.

Submit an Answer
2 answers

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.

  • Hi kamaln7, thank you for your response. I tried your script and yes the email was sent to my test account after 2 to 3 minutes. But using Easy SMTP plugin for wordpress and setup gmail smtp account I got this after test mail.

    SMTP connect() failed.

    I’m using SSL 465 on my setting.

    I also tried nc -vz 25 and the result is
    “Connection to 25 port [tcp/smtp] succeded!

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