在php中发送邮件不起作用

时间:2015-04-09 12:38:31

标签: javascript php email

我正在尝试从php发送电子邮件。邮件发送成功但从未发送。代码在下面..

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'];
        }
    }
}

一切都很好..并且echo消息被传递给callin php函数。我检查了$To变量确实有收件人的地址。所以请帮我跟踪一下这个问题。 :)

1 个答案:

答案 0 :(得分: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);

详细信息http://php.net/manual/en/function.mail.php