douchuitang0642 2016-01-24 09:27
浏览 60

如何在BootStrap 3中制作php ajax html电子邮件发送机制?

I have tried the following and I am unable to send the email still. My hosting provider permits phpmail as I get email from my other Joomla websites easily on this hosting.

Now here goes the public.html file:

   <html>
<head></head>
<body>

<script type="text/javascript">

    function submitForm(){
        var formName=document.forms["contact-us"];
        var name=formName.elements["name"].value;
        var email=formName.elements["email"].value;
        var msg=formName.elements["msg"].value;
        var phone = formName.elements["phone"].value;
        if(name=='' || email=='' || msg=='' || phone=='')
            alert("Please Input all fields");
        else
        {
            var dataString = 'name1='+ name + '&email1='+ email + '&msg1='+ msg + '&phone1='+ phone;
            $.ajax({
                type:"POST",
                url:"index.php",
                data:dataString,
                cache:false,
                success: function(){
                    alert("Email Sent Successfully!");  
                }
            });     
        }
        return false;
    }
    function Validate()
    {
        var stop=false;
        var x=document.forms["contact-us"]["email"].value;
        var p=document.forms["contact-us"]["phone"].value;
        var atpos=x.indexOf("@");
        var dotpos=x.lastIndexOf(".");
        if(isNaN(p)){
            alert("Please enter your correct phone number without '+' or '-'");
            stop=true;
        }else{
            var temp = Number(p);
            if(temp == 0){
                alert("Please provide a valid number.");
                stop=true;
            }
        }
        if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
        {
            alert("Not a valid e-mail address!");
            stop=true;
        }
        if(stop){
            return false;
        }
        else
            return submitForm();
    }

</script>

</body>

    </html>

and then I have some code in index.php file to deal with it. Here it goes:

<?php
if ($dataString)
 {
    $recipient = $_GET['sagar@sagaryadav.com'];
    $sender = $_GET'[Avighna Website'];
    $body = $_GET["$dataString"];
    $headers = 'From: info@avighnamerchandising.com' . "
" .
    'Reply-To: info@avighnamerchandising.com' . "
" .
    'X-Mailer: PHP/' . phpversion(5.5.31);
    $sendMail = mail($recipient, $sender, $body, $headers);
 }
?>

Now, what's wrong. Why am I not able to send this email from the form and what is it that needs to be there in the index.php file that would make it work?

  • 写回答

1条回答 默认 最新

  • douliao7930 2016-01-24 09:36
    关注
    <?php if ($_POST['dataString']) { 
    $recipient =$_POST['email1'];               $sender = 'Avighna Website'; 
     $body = $_POST['msg1']; 
     $headers = 'From: info@avighnamerchandising.com' . "
    " . 'Reply-To: info@avighnamerchandising.com' . "
    " . 'X-Mailer: PHP/' . phpversion(5.5.31);
     $sendMail = mail($recipient,       $sender, $body, $headers); } ?>
    

    You are using the post method nit get method

    评论

报告相同问题?

悬赏问题

  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置