# PHP MAIL issues..



## hockey97 (Aug 13, 2014)

Hi, how can I check for  errors from the PHP mail() function? 

Is there a log?  The function is always returning false and don't know why.
It's returning a false response in a if statement which means the e-mail failed to be sent.

I don't know how to debug this since there's no PHP errors being spit out. I checked my mail logs and found nothing there.

What can I do to debug it?    I had this working before but since I changed the apache server to use SSL / HTTPS and did change the mail server postfix and dovecot to use ssl. 

I am guessing I need to change the config settings? Right now I have the default seetings in place.


----------



## SirDice (Aug 14, 2014)

PHP scripts can be a bit tricky to debug. I'd "print" all the variables and arguments for mail() to the page as comments. That way you can look at the source of the page and see what's being used. It may just be an undefined variable or something like that.


----------



## hockey97 (Aug 14, 2014)

SirDice said:
			
		

> PHP scripts can be a bit tricky to debug. I'd "print" all the variables and arguments for mail() to the page as comments. That way you can look at the source of the page and see what's being used. It may just be an undefined variable or something like that.



I checked the variables and it's being passed in correctly. This script was working before. It's a registration script I did back in 2009.  I tested it back then and it was working. This past May I upgraded FreeBSD from 8.1 to 8.4. I have problems with many things. I fixed most of the problems and decided to add SSL / HTTPS to my web server. After doing this finding out many aspects of my websites malfunctioning. For example, my videos on my website won't play unless the user uses the http link.

The mail config is setup with :  localhost  port 25. I am guessing I need to change the config but I cannot verify the problems if there's no way to check out what mail() is spitting out. The script works fine and there's no php errors tossing out. The mail function is inside a if statement and seems to be always returning false.

I have it something like:


```
if(mail("to_mail@yahooo.com","Test_Mail","Hi, just testing this mail"))
{
  echo " Mail Successfully sent.";
}
else
{
  echo " Mail failed to be sent";
}
```

I am always getting the message: "Mail failed to be sent", sent to me when the script is running. There's no PHP errors showing.

Is there any way to get errors from Mail() ?

I just tried a var_dump() on the mail function and it returned NULL.


----------



## hockey97 (Aug 15, 2014)

I got it fixed... I found a log called httpd.error.  This had the errors of PHP mail() and it showed me that it was looking for mailparse.so file.  It gave me a failed to load error showing the directory path.

I checked that path and found no file by that name. I found another folder which is the folder for my previous PHP version that I had in the past. I found that file and copied it over to that directory. After that got it sending email's but had more errors. My mail server requires SSL.  So, I config to use port 465. It now fully works. I can send e-mail anywhere via PHP.


----------



## Carpetsmoker (Oct 1, 2014)

You probably don't want to use mail(), it has poor error reporting, is not very cross-platform, and security issues unless you do some escaping.

PHPMailer (https://github.com/PHPMailer/PHPMailer) or SWIFT mailer (http://swiftmailer.org/) are much better ways to send mails.


----------

