php mail() not working with Postfix, Dovecot, MySQL and SquirrelMail

Hi,

Can anyone help me out, I've followed the Postfix, Dovecot, MySQL and SquirrelMail guide on Ubuntu 16.04 and I can send and recieve emails using the domain/squirrelmail interface but I can't send it through a PHP mail() function.

I have set php.ini sendmail_path = "/usr/sbin/sendmail -t -i" . Getting really lost with where I am going wrong. The format of the PHP form is correct as far as I know. Any ideas? any other info I should post up here?

Thanks in advance!

5 Replies

Make sure you have put the configuration in the right php.ini. There are separate ones for the command-line, PHP-FPM, and the Apache PHP module. Using phpinfo() should show you the location.

It's possible, though unlikely, that /usr/sbin/sendmail is the problem; you can test it as follows:

$ /usr/sbin/sendmail -t -i
> From: me@mydomain.com
> To: me@someexternaldomain.com
> Subject: testing
> 
> This is a test.
> (Ctrl-D)

You should then receive this message at your me@someexternaldomain.com address.

When I create a it shows the loaded config path as /etc/php/7.0/apache2/php.ini which is the one I edited.

With regards to the sendmail from CLI, it sent the mail successfully! Leads me to think somehow php isn't being connected. I have attached the php.ini from /etc/php/7.0/apache2/ in case it helps to find the error. I've tried the sendmail_path with quotes without quotes to no avail.

[Pdo_mysql]
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=

[Phar]
; http://php.net/phar.readonly
;phar.readonly = On

; http://php.net/phar.require-hash
;phar.require_hash = On

;phar.cache_list =

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path= "/usr/sbin/sendmail -t -i"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
mail.log = /var/log/mail.log
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog

[SQL]
; http://php.net/sql.safe-mode
sql.safe_mode = Off

Hmm, not sure what the problem is then. It should be noted that SMTP, smtpport, and sendmailfrom are Windows-only - that could be causing trouble. I suggest comparing the php.ini for the command line (since that's working) with the one for Apache to see what's different. You actually shouldn't have to set anything, the defaults ought to work.

Thanks for the reply, unfortunately even after trying to comment out the SMTP, stmpport and sendmailport the issue was still there. The 2 files are the same.

If I run the command tail -f /var/log/syslog , I get this in the logs.

root@hydrogen:~# tail -f /var/log/syslog
May 22 10:29:54 hydrogen systemd[1]: Starting LSB: Apache2 web server...
May 22 10:29:54 hydrogen apache2[3199]:  * Starting Apache httpd web server apache2
May 22 10:29:56 hydrogen apache2[3199]:  *
May 22 10:29:56 hydrogen systemd[1]: Started LSB: Apache2 web server.
May 22 10:30:28 hydrogen postfix/sendmail[3263]: fatal: open /etc/postfix/main.cf: Permission denied
May 22 10:30:31 hydrogen postfix/sendmail[3265]: fatal: open /etc/postfix/main.cf: Permission denied
May 22 10:30:33 hydrogen postfix/sendmail[3267]: fatal: open /etc/postfix/main.cf: Permission denied
May 22 10:30:34 hydrogen postfix/sendmail[3269]: fatal: open /etc/postfix/main.cf: Permission denied
May 22 10:30:35 hydrogen postfix/sendmail[3271]: fatal: open /etc/postfix/main.cf: Permission denied
May 22 10:30:37 hydrogen postfix/sendmail[3273]: fatal: open /etc/postfix/main.cf: Permission denied

Do you know which command I can enter to give permission to Apache/fix this issue?

Thanks

Its done! I just simply reinstalled postfix and success! The Linode guide somewhere messed up or I did haha.

Thanks for all the help and support Vance :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct