javascript 需要 Mailhandler.php 帮助

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12548259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:29:28  来源:igfitidea点击:

Mailhandler.php assistance needed

javascriptforms

提问by user1691555

I do not understand how to make the MailHandler from my template's form submission work. I downloaded a template that I've been working on manually using DW6 alone, but I can't figure out exactly what to change in order to make the form in the Contact section send me the form info to my email address. Any help is much appreciated.

我不明白如何从我的模板的表单提交工作中制作 MailHandler。我下载了一个我一直单独使用 DW6 手动处理的模板,但我不知道要更改什么才能使“联系”部分中的表单将表单信息发送到我的电子邮件地址。任何帮助深表感谢。

From my index.html

从我的 index.html

<form action="#" id="ContactForm">  
                                    <div class="success"> Enviado!&nbsp; <strong>Nos contactaremos a la brevedad</strong></div> 
                                        <fieldset class="left"> 
                                                    <div class="block">
                                                    <label class="name">
                                                        <span class="textStyle3">Nombre</span>
                                                        <span class="bg"><input type="text" value="" class="input"></span>
                                                        <span class="error">*éste no es un nombre válido.</span> <span class="empty">*Campo Obligatorio.</span> </label>
                                                     <label class="email">
                                                        <span class="textStyle3">e-mail</span>
                                                        <span class="bg"><input type="text" value="" class="input"></span>
                                                        <span class="error">*Dirección de email no válida.</span> <span class="empty">*Campo Obligatorio.</span> </label>

                                                     </div>
                                                     <div class="block">
                                                     <label class="message">
                                                        <span class="textStyle3">Mensaje</span>
                                                        <span class="bg"><textarea rows="1" cols="2"></textarea></span>
                                                        <span class="error">*Este mensaje es muy corto.</span> <span class="empty">*Campo Obligatorio.</span> </label>
                                                     </div>
                                                      <div class="formBtn right">
                                                            <a href="#" data-type="submit" class="more">Enviar</a>
                                                      </div>
                                                      <div class="formBtn left">
                                                             <a href="#" data-type="reset" class="more">Limpiar</a>
                                                      </div>
                                            </fieldset>
                                        </form>

From my MailHandler.php

从我的 MailHandler.php

<?php
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";

if($_POST['name']!='nope'){
    $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
    $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}else{
    $headers = '';
}
if($_POST['state']!='nope'){        
    $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){        
    $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}    
if($_POST['fax']!='nope'){        
    $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
    $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}

if($_POST["stripHTML"] == 'true'){
    $messageBody = strip_tags($messageBody);
}

try{
    if(!mail($owner_email, $subject, $messageBody, $headers)){
        throw new Exception('mail failed');
    }else{
        echo 'mail sent';
    }
}catch(Exception $e){
    echo $e->getMessage() ."\n";
}
?>

From my scripts.js

从我的scripts.js

//forms
;(function($){
$.fn.forms=function(o){
    return this.each(function(){
        var th=$(this)
            ,_=th.data('forms')||{
                errorCl:'error',
                emptyCl:'empty',
                invalidCl:'invalid',
                notRequiredCl:'notRequired',
                successCl:'success',
                successShow:'4000',
                mailHandlerURL:'bin/MailHandler.php',
                ownerEmail:'[email protected]',
                stripHTML:true,
                smtpMailServer:'localhost',
                targets:'input,textarea',
                controls:'a[data-type=reset],a[data-type=submit]',
                validate:true,
                rx:{
                    ".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
                    ".state":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
                    ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
                    ".phone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
                    ".fax":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
                    ".message":{rx:/.{20}/,target:'textarea'}
                },
                preFu:function(){
                    _.labels.each(function(){
                        var label=$(this),
                            inp=$(_.targets,this),
                            defVal=inp.val(),
                            trueVal=(function(){
                                        var tmp=inp.is('input')?(tmp=label.html().match(/value=['"](.+?)['"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()
                                        return defVal==''?defVal:tmp
                                    })()
                        trueVal!=defVal
                            &&inp.val(defVal=trueVal||defVal)
                        label.data({defVal:defVal})                             
                        inp
                            .bind('focus',function(){
                                inp.val()==defVal
                                    &&(inp.val(''),_.hideEmptyFu(label),label.removeClass(_.invalidCl))
                            })
                            .bind('blur',function(){
                                _.validateFu(label)
                                if(_.isEmpty(label))
                                    inp.val(defVal)
                                    ,_.hideErrorFu(label.removeClass(_.invalidCl))                                          
                            })
                            .bind('keyup',function(){
                                label.hasClass(_.invalidCl)
                                    &&_.validateFu(label)
                            })
                        label.find('.'+_.errorCl+',.'+_.emptyCl).css({display:'block'}).hide()
                    })
                    _.success=$('.'+_.successCl,_.form).hide()
                },
                isRequired:function(el){                            
                    return !el.hasClass(_.notRequiredCl)
                },
                isValid:function(el){                           
                    var ret=true
                    $.each(_.rx,function(k,d){
                        if(el.is(k))
                            ret=d.rx.test(el.find(d.target).val())                                      
                    })
                    return ret                          
                },
                isEmpty:function(el){
                    var tmp
                    return (tmp=el.find(_.targets).val())==''||tmp==el.data('defVal')
                },
                validateFu:function(el){                            
                    el.each(function(){
                        var th=$(this)
                            ,req=_.isRequired(th)
                            ,empty=_.isEmpty(th)
                            ,valid=_.isValid(th)                                

                        if(empty&&req)
                            _.showEmptyFu(th.addClass(_.invalidCl))
                        else
                            _.hideEmptyFu(th.removeClass(_.invalidCl))

                        if(!empty)
                            if(valid)
                                _.hideErrorFu(th.removeClass(_.invalidCl))
                            else
                                _.showErrorFu(th.addClass(_.invalidCl))                             
                    })
                },
                getValFromLabel:function(label){
                    var val=$('input,textarea',label).val()
                        ,defVal=label.data('defVal')                                
                    return label.length?val==defVal?'nope':val:'nope'
                }
                ,submitFu:function(){
                    _.validateFu(_.labels)                          
                    if(!_.form.has('.'+_.invalidCl).length)
                        $.ajax({
                            type: "POST",
                            url:_.mailHandlerURL,
                            data:{
                                name:_.getValFromLabel($('.name',_.form)),
                                email:_.getValFromLabel($('.email',_.form)),
                                phone:_.getValFromLabel($('.phone',_.form)),
                                fax:_.getValFromLabel($('.fax',_.form)),
                                state:_.getValFromLabel($('.state',_.form)),
                                message:_.getValFromLabel($('.message',_.form)),
                                owner_email:_.ownerEmail,
                                stripHTML:_.stripHTML
                            },
                            success: function(){
                                _.showFu()
                            }
                        })          
                },
                showFu:function(){
                    _.success.slideDown(function(){
                        setTimeout(function(){
                            _.success.slideUp()
                            _.form.trigger('reset')
                        },_.successShow)
                    })
                },
                controlsFu:function(){
                    $(_.controls,_.form).each(function(){
                        var th=$(this)
                        th
                            .bind('click',function(){
                                _.form.trigger(th.data('type'))
                                return false
                            })
                    })
                },
                showErrorFu:function(label){
                    label.find('.'+_.errorCl).slideDown()
                },
                hideErrorFu:function(label){
                    label.find('.'+_.errorCl).slideUp()
                },
                showEmptyFu:function(label){
                    label.find('.'+_.emptyCl).slideDown()
                    _.hideErrorFu(label)
                },
                hideEmptyFu:function(label){
                    label.find('.'+_.emptyCl).slideUp()
                },
                init:function(){
                    _.form=_.me                     
                    _.labels=$('label',_.form)

                    _.preFu()

                    _.controlsFu()

                    _.form
                        .bind('submit',function(){
                            if(_.validate)
                                _.submitFu()
                            else
                                _.form[0].submit()
                            return false
                        })
                        .bind('reset',function(){
                            _.labels.removeClass(_.invalidCl)                                   
                            _.labels.each(function(){
                                var th=$(this)
                                _.hideErrorFu(th)
                                _.hideEmptyFu(th)
                            })
                        })
                    _.form.trigger('reset')
                }
            }
        _.me||_.init(_.me=th.data({forms:_}))
        typeof o=='object'
            &&$.extend(_,o)
    })
}
})(jQuery)
$(window).load(function(){
$('#ContactForm').forms({
    ownerEmail:'#'
})
})

回答by Syed Ashik Mahmud

In your scripts.js find this line ownerEmail:'#'

在你的 scripts.js 中找到这一行 ownerEmail:'#'

and in that field you give you your own email like ownerEmail:'[email protected]'

在该字段中,您可以为您提供自己的电子邮件,例如 ownerEmail:'[email protected]'

回答by fafchook

you need to place your email address on your index page (or contact.html) where the script is loaded. look for :

您需要将您的电子邮件地址放在加载脚本的索引页面(或 contact.html)上。寻找 :

<script>
    $(function(){


        //  Initialize Contact Form
        $('#YOUR_FORM_ID').forms({
            ownerEmail:'#' //CHANGE # TO YOUR E-MAIL
        });
    })
</script>