dthtvk3666 2018-05-11 10:56
浏览 102

PHP邮件代码不起作用

This is my current code. Why is it not working? It sends mail, but in the $message section it doesn't pull from $name, $phone, or $email. Also, on the email itself, the $from doesn't work. The only thing that works correctly is $to and $subject.

<?php 
if(isset($_POST['submit'])){
$to = "emailgoeshere@example.com";
$from = $_POST['email']; 
$name = $_POST['name'];
$subject = "Form submission";
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $name . " " . $phone . " has the email:" . "

" . $_POST['email'];

$headers = "From: <".$from. ">" ;
mail($to,$subject,$message,$headers);
echo "We have Recieved your Enquiry, We will get back to you soon. We Appreciate Your Patient Thank You.";
}
?>


<div class="right-wrapper">
                <div class="contact-form">
                    <p class="contact-form-info">Leave your contact info below, and we'll contact you shortly:</p>
                    <form action="https://www.forevrmarketing.com/webdesigndemo/eddy1155/functions/send-mail.php" method="post">
                    <input type="text" placeholder="Name" class="name" name="name" id="name">
                    <input type="email" placeholder="Email" class="email" class="email" id="email">
                    <input type="number" placeholder="Phone" id="phone" class="phone" class="phone" oninput="this.value=this.value.replace(/[^\d]/,'')" maxlength="15">
                    <input class="submit" type="submit" name="submit" value="Submit">

                    <div class="loader" disabled><i class="fa fa-spin fa-spinner" aria-hidden="true"></i></div>
                    <p class="form-details form-era">Call us at <strong style="font-weight: 600">+65 9691 1155</strong> Or <br><span class="wts"><img src="img/icon.png" alt="WhatsApp Icon"></span> <strong style="font-weight: 600">Whatsapp</strong> us</p>
                    <p class="reponse"></p>
                </div>
            </div>
  • 写回答

1条回答 默认 最新

  • duanbozhong9689 2018-05-11 11:17
    关注

    Two fields in your form are missing name attributes and thus cannot be referenced as $_POST['email'] and $_POST['phone'].

    <input type="email" placeholder="Email" class="email" class="email" id="email">
    <input type="number" placeholder="Phone" id="phone" class="phone" class="phone" oninput="this.value=this.value.replace(/[^\d]/,'')" maxlength="15">
    

    should be

    <input type="email" placeholder="Email" name="email" class="email" id="email">
    <input type="number" placeholder="Phone" id="phone" name="phone" class="phone" oninput="this.value=this.value.replace(/[^\d]/,'')" maxlength="15">
    

    This should solve $from, $phone and $email being empty.

    Also, in your $message line you could replace $_POST['email'] with $email.

    Finally, add a closing </form> to your code.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器