mail函数返回false

时间:2016-07-03 06:56:34

标签: php email

这里曾多次询问,但我找不到答案。 我试图添加标题等但似乎没有任何效果。 我的代码返回" false"每当我尝试发送邮件时。

    <?php   
    if(isset($_GET['action'])=='submitfunc') {
$EmailTo = prep($sObj->email);
$Subject = "The reason why your submission got rejected.";
$Message = Trim(stripslashes($_POST['Message'])); 
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webmaster@website.com>' . "\r\n";

// prepare email body text
$Body = "";
$Body.= "Message: ";
$Body.= $Message;

// send email 
$success = mail($EmailTo,$Subject,$Body,$headers);

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=succes.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
}else { ?>

  <div class="emailrejection">
                <form method="post" action="?action=submitfunc">

Dear <?php prep($sObj->username); ?>,   <br>            
                <textarea placeholder="Describe why the image got rejected...." name="Message" rows="3" cols="20" id="Message"></textarea> <br>
                All the best,,<br>
                Moderator <?php prep($uObj->username); ?><br>

                <input type="submit" name="submit" value="No + send message" class="btn btn-large btn-danger"  />
            </form>
  </div>

我认为错误在第3行。

$EmailTo = prep($sObj->email);

如果我将其替换为: $EmailTo = "myemail.gmail.com";外翻工作正常。

如果我回复$ EmailTo它也可以正常工作。为什么不能在邮件功能中使用它?

0 个答案:

没有答案