Question

I am using Digital Ocean to host a website, and I can't seem to get my php mail function to actually send the mail. It say that it was sent to postfix, but postfix doesn't seem to be sending it to the receiver.

I am running this code:

<?php
$headers = 'From: no-reply@diskise.com' . "\r\n" .
    'Reply-To: no-reply@diskise.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$mailed = mail("xxxxxx@gmail.com", "Welcome to Diskise", "Welcome to Diskise!\nI hope you enjoy your stay!", $headers);
if($mailed){
    echo "Email was sent!";
}else{
    echo "Email was not sent :(";
}

The output displays that the Email was sent!, I have changed sendmail_path in my php.ini file to this:

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

So, I conclude that it has to be something to do with my postfix configuration:

# 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

# TLS parameters
smtpd_tls_cert_file = /etc/ssl/certs/iRedMail_CA.pem
smtpd_tls_key_file = /etc/ssl/private/iRedMail.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
myhostname = diskise.com
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
myorigin = diskise.com
mydestination = $myhostname, localhost, localhost.localdomain, localhost.$myhostname
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
virtual_alias_domains =
allow_percent_hack = no
swap_bangpath = no
mydomain = diskise.com
mynetworks_style = host
smtpd_data_restrictions = reject_unauth_pipelining
smtpd_reject_unlisted_recipient = yes
smtpd_reject_unlisted_sender = yes
smtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, permit_sasl_authenticated
delay_warning_time = 0h
maximal_queue_lifetime = 4h
bounce_queue_lifetime = 4h
proxy_read_maps = $canonical_maps $lmtp_generic_maps $local_recipient_maps $mydestination $mynetworks $recipient_bcc_maps $recipient_canonical_maps $relay_domains $relay_recipient_maps $relocated_maps $sender_bcc_maps $sender_canonical_maps $smtp_generic_maps $smtpd_sender_login_maps $transport_maps $virtual_alias_domains $virtual_alias_maps $virtual_mailbox_domains $virtual_mailbox_maps $smtpd_sender_restrictions
smtp_data_init_timeout = 240s
smtp_data_xfer_timeout = 600s
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, check_helo_access pcre:/etc/postfix/helo_access.pcre
queue_run_delay = 300s
minimal_backoff_time = 300s
maximal_backoff_time = 4000s
enable_original_recipient = no
disable_vrfy_command = yes
home_mailbox = Maildir/
allow_min_user = no
message_size_limit = 15728640
virtual_minimum_uid = 2000
virtual_uid_maps = static:2000
virtual_gid_maps = static:2000
virtual_mailbox_base = /var/vmail
transport_maps = proxy:mysql:/etc/postfix/mysql/transport_maps_user.cf, proxy:mysql:/etc/postfix/mysql/transport_maps_domain.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql/virtual_mailbox_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql/virtual_mailbox_maps.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql/virtual_alias_maps.cf, proxy:mysql:/etc/postfix/mysql/domain_alias_maps.cf, proxy:mysql:/etc/postfix/mysql/catchall_maps.cf, proxy:mysql:/etc/postfix/mysql/domain_alias_catchall_maps.cf
sender_bcc_maps = proxy:mysql:/etc/postfix/mysql/sender_bcc_maps_user.cf, proxy:mysql:/etc/postfix/mysql/sender_bcc_maps_domain.cf
recipient_bcc_maps = proxy:mysql:/etc/postfix/mysql/recipient_bcc_maps_user.cf, proxy:mysql:/etc/postfix/mysql/recipient_bcc_maps_domain.cf
relay_domains = $mydestination, proxy:mysql:/etc/postfix/mysql/relay_domains.cf
smtpd_sender_login_maps = proxy:mysql:/etc/postfix/mysql/sender_login_maps.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_authenticated_header = no
smtpd_recipient_restrictions = reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, check_policy_service inet:127.0.0.1:7777, check_policy_service inet:127.0.0.1:10031, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10031
smtpd_tls_security_level = may
smtpd_tls_loglevel = 0
smtpd_tls_CAfile = /etc/ssl/certs/iRedMail_CA.pem
tls_random_source = dev:/dev/urandom
mailbox_command = /usr/lib/dovecot/deliver
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
smtpd_sasl_type = dovecot
smtpd_sasl_path = ./dovecot-auth
content_filter = smtp-amavis:[127.0.0.1]:10024
smtp-amavis_destination_recipient_limit = 1

I also edited this file /etc/postfix/virtual to look like this:

no-reply@diskise.com no-reply

So after everything is configured, and I restart postfix, and then run my php file I get the message Email was sent! but I never get the email.

I also do:

$ sendmail xxxxxx@gmail.com
Hello.

This is a test!

I then press CTRL+D to send it, and it doesn't go to my email. Any suggestions?

Here is the tail of /var/log/mail.log

Oct 30 22:25:11 localhost postfix/proxymap[19308]: warning: mysql:/etc/postfix/mysql/sender_bcc_maps_user.cf is unavailable. unsupported dictionary type: mysql
Oct 30 22:25:11 localhost postfix/cleanup[19411]: warning: proxy:mysql:/etc/postfix/mysql/sender_bcc_maps_user.cf lookup error for "www-data@diskise.com"
Oct 30 22:25:11 localhost postfix/cleanup[19411]: warning: EED3060D42: sender_bcc_maps lookup problem
Oct 30 22:25:11 localhost postfix/pickup[19153]: warning: maildrop/4272160D1E: error writing EED3060D42: queue file write error
Oct 30 22:25:11 localhost postfix/pickup[19153]: warning: EEF7460D42: message has been queued for 9 days
Oct 30 22:25:11 localhost postfix/pickup[19153]: EEF7460D42: uid=0 from=<root>
Oct 30 22:25:11 localhost postfix/proxymap[19308]: warning: mysql:/etc/postfix/mysql/sender_bcc_maps_user.cf is unavailable. unsupported dictionary type: mysql
Oct 30 22:25:11 localhost postfix/cleanup[19442]: warning: proxy:mysql:/etc/postfix/mysql/sender_bcc_maps_user.cf lookup error for "root@diskise.com"
Oct 30 22:25:11 localhost postfix/cleanup[19442]: warning: EEF7460D42: sender_bcc_maps lookup problem
Oct 30 22:25:11 localhost postfix/pickup[19153]: warning: maildrop/CFD8F60A8D: error writing EEF7460D42: queue file write error
Was it helpful?

Solution

From what can be seen in your logfile, your installation of postfix has errors, and the whole process of sending mail fails in it's initial stage.

You should probably fix that if you want to send any mail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top