duankeye2342 2013-06-13 09:49
浏览 30
已采纳

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

The form and the PHP code are working fine, but the only problem I am having with this is that it will not send an email to me nor to the person signing up. Please if you could look at the codes to see what I am doing wrong.

Thanks in advance.

This the 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>

And these are the PHP codes:

<?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:

"; foreach($fields as $a => $b)
{$body .= sprintf("%20s: %s
",$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条回答 默认 最新

  • douxian1770 2013-06-13 10:03
    关注

    Dear if you are working on a local server just like XAMPP or APPSERV or whatsoever you have to install mail server on you local machine

    and if you are working on a real host server make sure the the php setting in the server allow you to use mail function cuse many server has stop this function.

    so i recommend you to use smtp to send mail take a look here

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

    and there is a supper powerful library to send email PHPMailer

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备