0

I'm trying to send email using mail() function in php.

I'm on Localhost.

Here is my code :

$result = mail('recipient@gmail.com', 'Hello world', 'Some Message');
var_dump($result);  

It gives me this :

bool(false)

I'm facing this from last 2 days, please help !

My configuration of xampp is according to this link.

Nprogrammer
  • 13
  • 3
  • 7
  • I would recommend that you use a tried and tested mail lib instead, like PHPMailer, SwiftMailer or similar instead of the low level `mail()`-function. That will not only give you a way more verbose API, but it's also easier to debug and makes your code more portable since you then easily can use some SMTP-server, which is recommended and won't depend on any server configurations. – M. Eriksson Mar 15 '19 at 08:12
  • Can i use it with core Php, I've read some post regarding SwiftMailer, there are stuff related to OOP ? @ Magnus Eriksson – Nprogrammer Mar 15 '19 at 08:21
  • Both those libraries are just PHP without depending on anything else (other than a valid mail address). Just donwload it (or use composer) and follow their documentation. Yes, they are built with OOP, just like most libraries/code nowadays. – M. Eriksson Mar 15 '19 at 08:24
  • Okay ! let me try the PHPMailer , could you please share some useful stuff ? "@magnus Eriksson – Nprogrammer Mar 15 '19 at 08:39
  • I can recommend reading the documentation. They have all kinds of examples there. – M. Eriksson Mar 15 '19 at 08:51
  • I used the PHPMailer, and it worked , really happy to sort out this , thank you so much ! @Magnus Eriksson – Nprogrammer Mar 15 '19 at 11:49

1 Answers1

0

The reason is always the sendmail_from and sendmail_path are not correct with respect to your system in the php.ini settings even if the mail goes successfully but it will return false if the path is not correct. Please check those.

Ahmed Maruf
  • 481
  • 3
  • 14
  • _"The reason is always the sendmail_from"_ - That's a big claim! You mean that there is _no other_ possible explanation for why the `mail()`-function can return false? – M. Eriksson Mar 15 '19 at 08:26
  • Here is my configuration : sendmail_from = mehmoodsft@gmail.com. sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" – Nprogrammer Mar 15 '19 at 08:36
  • I have faced this problem several times only because of wrong configurations. i.e why I claim that. But in this case seems like configurtion is ok. Is that problem solved ? – Ahmed Maruf Mar 16 '19 at 08:21