dqwh1205 2017-04-05 14:59
浏览 41
已采纳

电子邮件PHP表单不起作用[重复]

This question already has an answer here:

I haven't written code in years, so I am going off old code from a project that is over 5 years old, so I am not surprised that it doesn't work; I would like some pointers on how to make it work, please.

Here is what I have in my HTML email form --

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

                                                <div class="form-group">
                                                    <!--<label for="contact_name">Name:</label>-->
                                                    <input type="text" id="contact_name" class="form-control" placeholder="Name" />
                                                </div>
                                                <div class="form-group">
                                                    <!--<label for="contact_email">Email:</label>-->
                                                    <input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
                                                </div>
                                                <div class="form-group">
                                                    <!--<label for="contact_message">Message:</label>-->
                                                    <textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
                                                </div>
                                                <button type="submit" class="btn btn-primary">Send</button>

                                        </form>

and here is what my PHP looks like --

 <?php

if(isset($_POST['send'])) {
   // Prepare the email
$to = ''foryourdayformals@gmail.com ';

$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
   $subject = 'Message sent from website';
   $message = $_POST['contact_message'];

$header = "From: $name <$mail_from>";

   // Send it
   $sent = mail($to, $subject, $message, $header);
   if($sent) {
   echo 'Your message has been sent successfully! <a href="http://www.foryourdayllc.com">Return to For Your Day, LLC Website</a>';
   } else {
   echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). <a href="http://www.foryourdayllc.com">Return to For Your Day, LLC Website</a>';
   }
}
?>

Any help is GREATLY appreciated! Thanks!

</div>
  • 写回答

1条回答 默认 最新

  • doubai9014 2017-04-05 15:02
    关注

    update

    $to = ''foryourdayformals@gmail.com ';
    

    to

    $to = 'foryourdayformals@gmail.com';
    

    and need to add name attribute for form . This update your form

    <form action="fydcontact.php" method="post">
    
                                                    <div class="form-group">
                                                        <!--<label for="contact_name">Name:</label>-->
                                                        <input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
                                                    </div>
                                                    <div class="form-group">
                                                        <!--<label for="contact_email">Email:</label>-->
                                                        <input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
                                                    </div>
                                                    <div class="form-group">
                                                        <!--<label for="contact_message">Message:</label>-->
                                                        <textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
                                                    </div>
                                                    <button type="submit" class="btn btn-primary" name ="send">Send</button>
    
                                            </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 VUE项目怎么运行,系统打不开