0

I wrote a simple test code for mail in PHP on my remote server RHEL 8. But when I trigger it doesn't sent mails to me. What is the issue can anyone tell me? Is there any configuration I need to do in php.ini file?

CODE

    <?PHP
       // the message
       $msg = "First line of text\nSecond line of text";

       // use wordwrap() if lines are longer than 70 characters
       $msg = wordwrap($msg,70);

       // send email
       mail("sudipta.s@gmail.com","My subject",$msg);

       ?>

I'm using PHP 7.2, RHEL 8, apache 2.4. Any clue to solve it?

ratna
  • 124
  • 4
  • 18
  • First off, check your server mail log – Ken Lee Mar 30 '22 at 11:41
  • RHEL 8 = Red Hat Enterprise Linux 8 (sorry, had to look that up) – KIKO Software Mar 30 '22 at 11:43
  • @KIKOSoftware yes – ratna Mar 30 '22 at 11:44
  • Mail was probably sent, but Google discarded it because, I assume, your mail server has no SPF, DKIM or DMARK, and therefore a poor reputation. – KIKO Software Mar 30 '22 at 11:46
  • @KIKOSoftware then what should I do to solve this issue? – ratna Mar 30 '22 at 11:48
  • 1
    Read the answers in the link that _Ivar_ gave you. It is helpful. But keep in mind that maintaining a reputable mail server can be a lot of work. Sometimes it is better to use third party services instead. – KIKO Software Mar 30 '22 at 11:49
  • This problem is actually unrelated to PHP, Apache or RHEL specifically. You need to install and correctly configure a mailserver on the machine (that can be done under any O/S and is independent of your web application environment). Or use a 3rd party service instead (probably easier). – ADyson Mar 30 '22 at 11:51

0 Answers0