这段代码我在哪里出错

时间:2015-10-13 19:09:55

标签: php forms

我正在尝试使用此代码将表单详细信息发送到多个电子邮件地址,它不起作用,任何人都可以教我在哪里出错了。我的上一个问题被标记为重复,但它没有回答我的问题,请帮助我。它在运行时不会发送到任何电子邮件地址。

    <?php

$EmailFrom = "WelcomeToFarla,";
$EmailTo = array('prospects@farla.co.uk' , 'gezzietremors@hotmail.com' , 'prospects@farla.co.uk'); 
$Subject = "Online Form Submission";
$Name = Trim(stripslashes($_POST['Name'])); 
$Email = Trim(stripslashes($_POST['Email'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";

// send email 
$success = ($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

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

1 个答案:

答案 0 :(得分:3)

除非您的代码被意外截断,否则您实际上并未调用邮件功能。这样:

// send email 
$success = ($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

应该是这样的:

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");