Question

I can't receive emails Ubuntu 18.04 with Postfix (PHP 7.2-FPM, NGINX)

Hello everyone, I spend whole night trying to get it work and I no success… I don’t know whats wrong and asking you for help.

What I want to do is make php mail() form to work, but I’m not receiving mail() function submitted.

PHP Settings

sendmail_path = /usr/sbin/sendmail -t -i

PHP Mail Script:

   <?php
        ini_set( 'display_errors', 1 );
        error_reporting( E_ALL );
        $from = "arnas@mydomain.com";
        $to = "arnas@mydomain.com";
        $subject = "Testing email #1";
        $message = "Test message";
        $headers = "From:" . $from;
        mail($to,$subject,$message, $headers);
        echo "Test email sent";
    ?>

Postfix installation:

sudo apt-get update
sudo apt install -y mailutils

Select Internet Site and press ENTER. System mail name: mydomain.com

sudo nano /etc/postfix/main.cf

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mydomain.com, mydomain.com, localhost.localdomain, localhost
relayhost = 
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4

After all configuration I have tried to send test email also from command line as follows:

echo "Test Email message body" | mail -s "Email test subject" name@mydomain.com

After that I viewed log sudo tail /var/log/mail.log and it prints:

Jan 21 09:23:42 DROPLET-LEMP-NEW postfix/pickup[16088]: EFD2FFF3A7: uid=0 from=<root@DROPLET-LEMP-NEW>
Jan 21 09:23:42 DROPLET-LEMP-NEW postfix/cleanup[16126]: EFD2FFF3A7: message-id=<20200121092342.EFD2FFF3A7@mydomain.com>
Jan 21 09:23:42 DROPLET-LEMP-NEW postfix/qmgr[16089]: EFD2FFF3A7: from=<root@DROPLET-LEMP-NEW>, size=346, nrcpt=1 (queue active)
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/local[16128]: EFD2FFF3A7: to=<arnas@mydomain.com>, relay=local, delay=0.04, delays=0.02/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "arnas")
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/cleanup[16126]: 024D7FF3A8: message-id=<20200121092343.024D7FF3A8@mydomain.com>
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/qmgr[16089]: 024D7FF3A8: from=<>, size=2117, nrcpt=1 (queue active)
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/bounce[16129]: EFD2FFF3A7: sender non-delivery notification: 024D7FF3A8
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/qmgr[16089]: EFD2FFF3A7: removed
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/smtp[16131]: 024D7FF3A8: to=<root@DROPLET-LEMP-NEW>, relay=none, delay=0.02, delays=0/0.01/0.01/0, dsn=5.4.6, status=bounced (mail for DROPLET-LEMP-NEW loops back to myself)
Jan 21 09:23:43 DROPLET-LEMP-NEW postfix/qmgr[16089]: 024D7FF3A8: removed

I have no clue whats going on here :(


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.

I have the same problem as you, but me i use debian, did you find a solution?

No one knows? 2020-01-22 02:26:13 H=(domain.com) CV=no F=root@domain.com rejected RCPT arnas@domain.com: Forged host name

I also have tried sendmail but still can’t get it to work. Also, forgot to mention that I’m using mail server IP different from droplet. Also ipv6 is enabled, I dunno if that can impact email delivery :|