0

I am trying to send an email from php. The mail sends successfully but is never delivered. The code is below..

if(isset($_POST["Referred"])) {
    if(isset($_POST["RequestedEmail"])) {
        $messagebody="You are invited to join Fasttask. please click on the link below \n http://www.fasttask.net/EmailRequestRedirect.php?User_Id=".$_SESSION['user_id'];
        $To=$_POST["RequestedEmail"];

        if(mail($To,"Join Fasttask",  $messagebody)) { 
            $query="Update monthlygiveaway set TotalReferrals=TotalReferrals+1 where UserId=?";
            $stmt=$mysqli->stmt_init();
            $stmt->prepare($query);
            $stmt->bind_param('i', $UserId);
            $UserId=$_SESSION['user_id'];
            $stmt->execute();
            echo"Successfully sent mail:".$To;
        } else {
            echo "Failed to send mail";echo $_SESSION['user_id'];
        }
    }
}

Everything goes fine.. and the echo message is delivered to callin php function. I checked so the $To variable does have the address of the recipient. So please help me to trace the issue. :)

MKroeders
  • 7,562
  • 4
  • 24
  • 39
spiral
  • 9
  • 3
  • 1
    Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Apr 09 '15 at 12:39
  • @Fred-ii- dear I included the suggested lines but not error reports – spiral Apr 09 '15 at 12:50
  • Are you running this from your own machine or a hosted service? Did you check your Spam? Did you start the session? Not having a `From:` in headers could be why. Many services will consider it as spam and discarded. – Funk Forty Niner Apr 09 '15 at 12:52
  • Could be your mail server? You need to check any error logs from many different places, like, again, _mail server_... – bcesars Apr 09 '15 at 13:08
  • @Fred-ii- yes I checked the spam folder but not there.. I am new to php I have migrated from asp.net.. so not very clear yet – spiral Apr 09 '15 at 13:20
  • @Fred-ii- Yes I am running it from the hosted service. – spiral Apr 09 '15 at 13:23
  • Check your logs and/or contact your host. There's nothing more I can say or do to help. Good luck. – Funk Forty Niner Apr 09 '15 at 13:24

1 Answers1

0
Have you try header parameter? may be it works.



 $to      = 'nobody@example.com';

    $subject = 'the subject';

    $message = 'hello';

    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();


mail($to, $subject, $message, $headers);

For more detail http://php.net/manual/en/function.mail.php

Zealous System
  • 2,080
  • 11
  • 22