Mail () does not work on the new server

Maybe this is a stupid question, but I can not find the reason why the php mail function does not work. I have a nginx server on debian squeeze, I moved to it recently. I tried simple mail execution, but it returns false.

if(mail(' test@email.com ', 'test-subject', 'test-text-blablabla')) echo 'ok'; else echo 'bad'; 

What can I do with it?

Thanks.

section of my php.ini mail:

 [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 = ; 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(), even in safe mode. ;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 = 
+7
source share
1 answer

Ok, I did it. How I did it for debian squeeze with nginx server: (all the commands that I execute as root)

First of all you need to install sendmail

 apt-get install sendmail 

Next, you should configure this file, which was easier than I thought.

 sendmailconfig 

Okay, the next step I took is configuring php.ini (I'm not a great admin, I'm new, so I don't know if this is necessary or not).

I have installed

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

Well, from now on, theoretically, you can send emails, but for my case this led to a 504 HTTP error gateway timeout. But, as I found out much later, e-mail has already appeared in the mailbox. So my test php file:

 <?php mail(' myWorkingEmail@example.com ', 'test', 'you done that'); echo 'ok'; // I use this to check that script is end the execution ?> 

This is pretty clear.

The next problem is error 504. I go to the log files

 nano /var/log/mail.log 

and here I find this error (this is not the only error, but it is responsible for error 504):

 sm-msp-queue[***]: My unqualified host name (myhostname) unknown; sleeping for retry 

Then, to find how I can solve this problem: http://forums.fedoraforum.org/archive/index.php/t-85365.html last comment on this page.

Or other words I made:

 nano /etc/hosts 

and in this file I change the order of the hosts

 127.0.0.1 my_ip localhost myhostname 

save, do. open your test php file, there is no 504 error, and emails are the income to send by email in the mail program. As I said, I'm a newbie and this may not work for you, but it works for me anyway. Of course, this is not the final configuration. I hope you find this helpful.

+23
source

All Articles