没有从PHP代码收到电子邮件

时间:2013-06-13 09:49:21

标签: php email

表单和PHP代码工作正常,但我遇到的唯一问题是它不会向我发送电子邮件,也不会向注册的人发送电子邮件。如果你能查看代码,看看我做错了。

提前致谢。

这是HTML。

<div id="formWrapper">

<form action="formprocess.php" method="post">


  <fieldset class="first">
  <h3>Welcome to the SBOCC Questions & Comments Page.</h3>
  <h4>Please fill out the form below with your question(s) or comment(s)<br> 
  so that you may receive an answer. Shalom (Peace). BLESS THE COMFORTER.
  </h4>
  <label class="labelOne" for="name">Your Name:</label>
  <label class="two" for="optional">(Required)</label>
  <input name="name" />

  <label for="email">Your Email:</label>
  <label class="three" for="required">(Required)</label>
  <input name="email" />

  <label for="questionscomments">Questions/Comments:</label>
  <textarea name="speak"></textarea>      
  </fieldset>

  <fieldset>
  <input class="btn" name="submit" type="submit" value="Send Email" />
  <input class="btn" name="reset" type="reset" value="Clear Form" />
  </fieldset>

  <fieldset class="second">
  <h4>Would you like to be added to our mailing list?<h4>
  <input class="ckbox" type="checkbox" name="mailing" value="yes" checked="yes" /> Yes
  <input class="ckbox" type="checkbox" name="mailing" value="no" /> No
  </fieldset>

这些是PHP代码:

<?php

$to = "shealtielyisrael@gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "Contact The SBOCC";


$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"speak"} = "questions/comments";
$fields{"mailing"} = "newsletter";


$body = "We have received the following information:\n\n"; foreach($fields as $a => $b)
{$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }


$headers2 = "From: noreply@thesbocc.com";
$subject2 = "Thank you for contacting The SBOCC";
$autoreply = "Thank you for contacting us. Your question(s)/comment(s) has been     received. Shalom. Bless the comforter";

if($name == '') {print "You have not entered a name, please go back and try again";}
else {
 if($from == '') {print "You have not entered an email, please go back and try      again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.html");}
else
{print "We encountered an error sending your mail, please notify shealtielyisrael@gmail.com";}
}
}

?>

1 个答案:

答案 0 :(得分:0)

亲爱的,如果您正在使用本地服务器,就像XAMPP或APPSERV一样,或者您必须在本地计算机上安装邮件服务器

如果您正在使用真正的主机服务器,请确保服务器中的php设置允许您使用邮件功能cuse许多服务器已停止此功能。

所以我建议你使用smtp发送邮件看看这里

http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

并且有一个超级强大的库来发送电子邮件PHPMailer

https://code.google.com/a/apache-extras.org/p/phpmailer/