duanhuan5409 2015-04-26 10:16
浏览 31

用.js验证的php邮件 - >看不出任何错误

I got this piece of code from a free template and I followed all the instructions that came with it, everything seems fine but mail doesn't go trough. HTML:

                <!--Start Contact form -->                                                      
<form name="enq" method="post" action="email/" onsubmit="return validation();">
  <fieldset>

    <input type="text" name="name" id="name" value=""  class="input-block-level" placeholder="Name.." />
    <input type="text" name="email" id="email" value="" class="input-block-level" placeholder="Email.." />
    <textarea rows="11" name="message" id="message" class="input-block-level" placeholder="Message.."></textarea>
    <div class="actions">
    <input type="submit" value="Send!" name="submit" id="submitButton" class="btn btn-info pull-right" title="Send!" />
    </div>

    </fieldset>
</form>                  
            <!--End Contact form -->

PHP

    <?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name.'<'.$email.'>';

 $to="email@sample.com";
 $subject="Enquiry!";
 $headers  = 'MIME-Version: 1.0' . "
";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
 $headers .= "From: ".$email_from."
";
 $message="   

         Name:
         $name     
         <br>
         Email-Id:
         $email        
         <br>
         Message:
         $query        

   ";
    if(mail($to,$subject,$message,$headers))
        header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
    else
        header("Location:../contact.php?msg=Error To send Email !");
        //contact:-your-email@your-domain.com
 }
?>

JavaScript

 function validation()
 {

    var contactname=document.enq.name.value;
    var name_exp=/^[A-Za-z\s]+$/;
    if(contactname=='')
    {
        alert("Name Field Should Not Be Empty!");
        document.enq.name.focus();
        return false;
    }
    else if(!contactname.match(name_exp))
    {
        alert("Invalid Name field!");
        document.enq.name.focus();
        return false;
    }

    var email=document.enq.email.value;
    //var email_exp=/^[A-Za-z0-9\.-_\$]+@[A-Za-z]+\.[a-z]{2,4}$/;
    var email_exp=/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if(email=='')
    {
        alert("Please Enter Email-Id!");
        document.enq.email.focus();
        return false;
    }
    else if(!email.match(email_exp))
    {
        alert("Invalid Email ID !");
        document.enq.email.focus();
        return false;
    }


    var message=document.enq.message.value;
    if(message=='')
    {
        alert("Query Field Should Not Be Empty!");
        document.enq.message.focus();
        return false;
    }
    return true;
 }

I don't get any errors but mail doesn't simply go trough, checked spam etc.

  • 写回答

2条回答 默认 最新

  • dongshan2004 2015-04-26 10:23
    关注

    I hope you changed

    $to="email@sample.com";
    

    to your actual e-mail.. I can't see anything else.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用