我承认我不是最好的PHP,但我所做的通常对我来说效果很好,因为客户只需要发送到他们的电子邮件的信息,并且安全问题可以很好地阻止垃圾邮件远离他们的收件箱。但由于某种原因,这段代码不起作用,我无法弄清楚原因。具有不同变量的相同代码在我拥有的另一个站点上并且经过测试和工作。有没有人有任何建议?
<form action="submit_form.php" method="POST" >
<p>Name<br /><input type="text" name="name" required /></p>
<p>Email Address<br /><input type="text" name="email" required /></p>
<p>Phone Number<br /><input type="text" name="phone" required /></p>
<p>County<br /><input type="text" name="county" required /></p>
<p>Annual Income<br /><input type="text" name="income" required /></p>
<p>What is 4 + 1? (anti-spam)<br /><input type="text" name="answer" required /></p>
<input type="submit" value="Take The First Step" />
</form>
<?php # BOOST
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$county = $_POST['county'];
$income = $_POST['income'];
$correct_answer = '5';
$answer = $_POST['answer'];
if ($correct_answer != $answer) {
die("You're not a valid user of this site!");
}
else {
$to = "glenn@boostbizseo.com";
$subject = "USDA LOANS";
$message = "USDA LOANS:\n
Name: $name
Email: $email
Phone: $phone
County: $county
Annual Income: $income";
$from = "USDA Loans";
mail($to,$subject,$message,$headers);
echo "Thank you for getting in contact with us. We will be in contact with you soon regarding your USDA Loan! <a href=http://www.usdaloansmo.com>Click Here</a> to go back to our website!";
}
?>
答案 0 :(得分:1)
$from = "someonelse@example.com"; //email ID
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
我相信这会奏效。
答案 1 :(得分:0)
这是错误的:
$from = "USDA Loans";
mail($to,$subject,$message,$headers);
您不使用$from
,$headers
未定义。
答案 2 :(得分:0)
以下是使用php发送电子邮件的方式。
$to="some@domain.com";
$subject="Your subject";
$header="from: ABCName <me@mydomain.com>";
$message="Message \r\n";
$sentmail = mail($to,$subject,$message,$header);
if($sentmail)
{
echo "Done";
}
else
{
echo "Oops, Something went wrong";
}