-1

I have a contact form. It works fine on 1 of the 2 servers I use. But not on the second one. And the second one is the one I want to keep in the end. Of course... How can that be? I tried to switch the php versions but still no change. At the moment: 7.2.12

Thanks for help.

<?php
    if (isset($_POST['submit'])) {  
        $name = $_POST['name'];
        $mailFrom = $_POST['email'];
        $message = $_POST['message'];

        $mailTo="john.doe@example.com";
        $subject="Message Sent From a Pilgrim Diaries User.";
        $txt = "name: ".$name."\n"."Email: ".$mailFrom."\n"."sent the following: "."\n\n".$message;
        $headers= "From: ".$mailFrom;

        mail($mailTo, $subject, $txt, $headers);

        header("Location: index.html?Mailsend");
    }
?>

Here is a screen capture of my settings:

Screen capture of the server settings

Didier Tibule
  • 101
  • 1
  • 11
  • please post the error – Joe Dec 10 '18 at 07:54
  • I suppose that second server does not allow to use mail() function – Alex Slipknot Dec 10 '18 at 07:58
  • @Joe That's the thing too. No error. It goes to the code seemingly without problem but doesn't send any e-mail... – Didier Tibule Dec 10 '18 at 07:59
  • @DidierTibule check if sendmail is installed, or maybe check the log of the webserver – Joe Dec 10 '18 at 08:00
  • @Alex Slipknot. I'm a bit new at this. How can I check that? And why a server wouldn't want to allow e-mail; what could be the problem? – Didier Tibule Dec 10 '18 at 08:01
  • https://responsive-muse.com/2017/01/21/how-to-check-if-php-mail-function-is-enabled-in-your-server/ might help you – Alex Slipknot Dec 10 '18 at 08:03
  • Another question (may look dumb but it has to be asked) Are you sure the webmail server is not blacklisted? Have you check the spam inbox? – Richard Dec 10 '18 at 08:10
  • @Alex Slipknot. Thanks I tried it. This time I got this error message: **Warning: mail(): headers parameter must be string or array in /srv/disk1/2884475/www/pilgrim-diaries.dx.am/test.php on line 7 Message delivery failed..** Line 7 being: **if (mail($to, $subject, $body, $header)) {** Does that means that mail isn't supported? Because I went in the settings and found this line: **Sendmail path /usr/local/bin/sendmail (SMTP is enabled, free type accounts may send up to 31 emails a month)** – Didier Tibule Dec 10 '18 at 08:22
  • @vincent-decoplus. Yes I checked, because the one server functioning was, yes, sending the mail in the junk box.... – Didier Tibule Dec 10 '18 at 08:24
  • @DidierTibule try setting headers via an array- I reckon`$mailFrom` isn't a value you're expecting on the server that's failing ... – treyBake Dec 10 '18 at 08:36
  • @treyBake. I tried that: **mail("Myemail@blabla.com", "subject", "message,"header");** Myemail being a valid email and subject,message,header being normal string. Didn't work that way either.... – Didier Tibule Dec 10 '18 at 08:51
  • @DidierTibule have you tried a manual mailsend? e.g. `mail('youremail@domain.com', 'test', 'test)`? (by manual I mean no use of variables, just putting in strings) – treyBake Dec 10 '18 at 08:52

1 Answers1

0

Lets start from beginning,

First check if sendmail is properly configured and working, run below code on terminal to send mail directly from terminal,

echo "Mail From Terminal" | mail -s subject user@gmail.com

If above sends mail then your server sendmail is properly configured. Else configure it. Then check if php is sending mail, try running from terminal,

php -r "mail('test@gmail.com', 'Subject', 'Mail from PHP through terminal')"'

If above works, then you are good to go. PHP is able to send mail. Else check your php.ini configuration.

Now, if above all works. There must be SELinux blocking apache to send mail, try running from terminal,

restorecon /usr/sbin/sendmail
setsebool -P httpd_can_sendmail 1
setsebool -V httpd_can_sendmail 1

Now, try running your script again.

In case, any of the above commands fail silently, check your server logs and reply.

Dr. DS
  • 984
  • 1
  • 13
  • 31