0

I am using PHP 5.4.35-0+deb7u2 on Debian 7.0. I use the following PHP code to send a message.

    $to = $emailAddress;
    $subject = "Registration";
    $message = "Dear " . $firstname . " " . $lastName .",\n\n" .
        "Thank you for registering for our program.\n\n" .
        "To complete your registration, please confirm your registration using the following activation code.\n\n" .
        $randomActivationCode . "\n\n" . 
        "at the following link.\n\n" . $Link . "\n\n" .
        "If you did not register for our program, please accept our apologies and disregard this message\n\n" .
        "Have a wonderful day!\nCompany name.\n";

    $from = "me@yahoo.com";
    $headers = "From:" . $from;

    $mailDelivery=mail($to,$subject,$message,$headers);
    if ($mailDelivery)
    {
        ?>
        <script type="text/javascript">
        document.location.href="http://home.com/Prewelcome.php";
        </script>
        <script type="text/javascript">
        alert("Thank you for your interest in our program.\nTo complete your registration, please check your email.");
        document.location.href="Subscriptions.php";
        </script>
        <?php
    }
    else
    {
        ?>
        <script type="text/javascript">
        alert("Mail delivery failed");
        </script>
        <?php
    }

I get the alert box "Thank you for your interest in our program.\nTo complete your registration, please check your email." but the email never shows up. (I am using my email address as the recipient.)

I also edited php.ini and made sure that

sendmail_path = /usr/sbin/sendmail

was included and that /usr/sbin/sendmail exists. After doing this, I also restarted apache with

sudo /etc/init.d/apache2 restart

I also did the following test

sendmail me@gmail.com

from the command line and the mail did show up in my mail box.

I also ran

sudo cat /var/log/apache2/error.log

and there were no errors.

However the mail I send from my php file never shows up in my mail box.

OtagoHarbour
  • 3,969
  • 6
  • 43
  • 81
  • Did you check your `junk` folder? Edit: you can not use ...@yahoo.com on your from part without smtp authentication on yahoo server. That is why gmail blocks your basic php mail. Try phpmailer or swiftmailer. – HddnTHA Dec 21 '14 at 21:37
  • Sorry . I meant to mention that I checked my spam folder but there is nothing there. Thanks, – OtagoHarbour Dec 21 '14 at 21:39
  • And what about `/var/mail/root|user`? Or `/var/spool/mail/user`? – Bas van Dorst Dec 21 '14 at 21:40
  • PLEASE, man, dont do this in javascript, thats horrible and mad, use `header('Location: yourlocation.php?done');` (or `?fail`, but not JS ...) – Bobot Dec 21 '14 at 21:52
  • Thank you, HddnTHA and Bas van Dorst. /var/spool/mail/www-data contained the reason. "Action: failed Status: 5.7.1 Remote-MTA: dns; gmail-smtp-in.l.google.com Diagnostic-Code: smtp; 550-5.7.1 Unauthenticated email from yahoo.com is not accepted due to domain's 550-5.7.1 DMARC policy. Please contact administrator of yahoo.com domain if 550-5.7.1 this was a legitimate mail. Please visit 550-5.7.1 http://support.google.com/mail/answer/2451690 to learn about DMARC 550 5.7.1 initiative. q8si18262537qco.8 - gsmtp" – OtagoHarbour Dec 21 '14 at 22:43
  • The email shows up when I change the from address but perhaps this is not that secure. I will look into phpmailer. Thanks again, – OtagoHarbour Dec 21 '14 at 23:13

0 Answers0