向电子邮件提交HTML5表单(通过php?) [英] Submitting HTML5 forms to email (via php?)

查看:146
本文介绍了向电子邮件提交HTML5表单(通过php?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建HTML5表单,该表单提交基本的供应商信息而无需打开用户的电子邮件客户端,并在表单提交时使用已提交(或类似内容)确认消息。从我的研究中,我发现我需要为此使用PHP,但对于如何实现PHP脚本我无能为力。



以下是我的表单:

 < form id =vendorInfo action =process_form_vendor.phpmethod =post> 
< label for =vendorName>供应商名称:< / label>
< br />
< input id =vendorNamename =vendorNametype =textmaxlength =30required>
< br />
< label for =contactName>联络人名称:< / label>
< br />
< input id =contactNamename =contactNametype =textmaxlength =35required>
< br />
< label for =vendorType>组织类型:< / label>
< br />
< select id =vendorTypename =vendorType>
< option value =carrier>
保险公司
< / option>
< option value =tech_crm>
技术/ CRM管理
< / option>
< option value =leadProvider>
潜在客户
< / option>
< option value =info_comm>
信息/通讯
< / option>
< option value =other>
其他(请在下面描述)
< / option>
< / select>
< br />
< label for =other1>其他单位类型:< / label>
< br />
< input id =other1name =other1type =textmaxlength =25>
< br />
< label for =email>电子邮件:< / label>
< br />
< input id =emailname =emailtype =emailmaxlength =30required>
< br />
< label for =phone>电话:< / label>
< br />
< input id =phonename =phonetype =telmaxlength =12required placeholder =xxx-xxx-xxxx>
< br />
< label for =questions>有任何问题或意见?将它们留在这里:< / label>
< br />
< textarea id =questionsname =questionsrows =10maxlength =300>< / textarea>
< br />
< br />
< fieldset id =selectionBox>
< legend id =packageSelect>
以下赞助包可用于销售峰会;联络< a href =example@domain.com> Amanda< / a>定价和详细信息:
< / legend>
< input type =radioname =packageSelectvalue =Bronze Packagechecked>& nbsp; Bronze
< br />>
< br />
< input type =radioname =packageSelectvalue =Silver Package>& nbsp; Silver
< br />
< br />
< input type =radioname =packageSelectvalue =Gold Lunch Package>& nbsp; Gold& nbsp;(早餐;独家赞助)
< br />
< br />
< input type =radioname =packageSelectvalue =Gold Breakfast Package>& nbsp; Gold& nbsp;(午餐;独家赞助)
< br />
< br />
< input type =radioname =packageSelectvalue =Gold Trade Show Package>& nbsp; Gold& nbsp;(trade& nbsp; show; exclusive sponsor)
< ; /字段集>
< br />
< button type =submit>提交< / button>& nbsp;< button type =reset>重设< / button>< br />



这里是PHP脚本我写道:

 <?php 

if(!isset($ _ POST ['提交']))
{
echo错误;您需要提交表单!;
}

$ vendorName = $ _POST ['vendorName'];
$ contactName = $ _POST ['contactName'];
$ vendorType = $ _POST ['vendorType'];
$ other1 = $ _POST ['other1'];
$ email = $ _POST ['email'];
$ phone = $ _POST ['phone'];
$ questions = $ _POST ['questions'];
$ packageSelect = $ _POST ['packageSelect']; (空($ contactName)||(空($ vendorType)||(空($ email)||(空($ phone)||($)空($ packageSelect)){
echo供应商名称,联系人名称,供应商类型,电子邮件,电话和包装选择是强制性的!;
exit;
}

$ email_from ='example@domain.com';
$ email_subject ='2014 SMS Sales Summit - New Vendor Reservation Request';
$ email_body =您已收到新的供应商预订请求2014 $ SMS销售高峰会从$ contactName at $ vendorName.\\\

Vendor Type:$ vendorType\\\

其他供应商类型:$ other1\\\

电子邮件地址:$ email \\\

电话号码:$ phone\\\

其他问题:$ questions \\\

赞助级别:$ packageSelect \\\


$ to ='example@domain.com';
$ headers =$ email_from \r\\\
;
$ 。回复: $ email \r\\\
;

mail($ to,$ email_subject,$ email_body,$ headers);
header('Location:thank-you.html');



?>

我很确定我已经正确设置了所有提交的信息'input'字段,但我不确定是否已经为单选按钮和下拉选择器正确实现了这一点。对此实施的任何帮助将非常感激。谢谢!

解决方案


  • < form action =method =postid =vendorInfo> //


  • 为您的所有输入字段赋予name属性:



    < input type =textname =whatever> //


  • 然后通过php中的post方法捕获这些

     <?php 
    if(isset($ _ POST ['your_submit_name']))
    {
    $ input_field = $ _ POST ['your_input_field_name'];
    $ to =somebody@example.com;
    $ subject =你的主题;
    $ message =你好邮件!。 \r\\\
    ;
    $ message。= $ input_field。\r\\\
    ;
    $ headers =From:webmaster@example.com。 \r\\\
    ;
    邮件($ to,$ subject,$ message,$ headers);
    ?>


    I'm attempting to create an HTML5 form that submits basic vendor information without opening the user's email client, and with a "Submitted" (or something of the like) confirmation message as the form submits. From my research, I've found that I'd need to use PHP for this, but I'm clueless as to how to implement the PHP scripts.

    Here's my form:

    <form id="vendorInfo" action="process_form_vendor.php" method="post">
        <label for="vendorName">Vendor Name:</label>
        <br />
        <input id="vendorName" name="vendorName" type="text" maxlength="30" required>
        <br />
        <label for="contactName">Contact Name:</label>
        <br />
        <input id="contactName" name="contactName" type="text" maxlength="35" required>
        <br />
        <label for="vendorType">Organization Type:</label>
        <br />
        <select id="vendorType" name="vendorType">
            <option value="carrier">
                    Insurance Carrier
            </option>
            <option value="tech_crm">
                    Technology/CRM Management
            </option>
            <option value="leadProvider">
                    Lead Provider   
            </option>
            <option value="info_comm">
                    Information/Communication
            </option>
            <option value="other">
                    Other (please describe below)
            </option>
        </select>
        <br />
        <label for="other1">Other Organization Type:</label>
        <br />
        <input id="other1" name="other1" type="text" maxlength="25">
        <br />
        <label for="email">Email:</label>
        <br />
        <input id="email" name="email" type="email" maxlength="30" required>
        <br />
        <label for="phone">Phone:</label>   
        <br />  
        <input id="phone" name="phone" type="tel" maxlength="12" required placeholder="xxx-xxx-xxxx">
        <br />
        <label for="questions">Any questions or comments? Leave them here:</label>
        <br />
        <textarea id="questions" name="questions" rows="10" maxlength="300"></textarea>
        <br />
        <br />
    <fieldset id="selectionBox">
        <legend id="packageSelect">
        The following sponsorship packages are available for the Sales Summit; contact <a href="example@domain.com">Amanda</a> for pricing and                              details: 
        </legend>
        <input type="radio" name="packageSelect" value="Bronze Package" checked>&nbsp;Bronze
        <br />
        <br />
        <input type="radio" name="packageSelect" value="Silver Package">&nbsp;Silver
        <br />
        <br />
        <input type="radio" name="packageSelect" value="Gold Lunch Package">&nbsp;Gold&nbsp;(breakfast; exclusive sponsorship)
            <br />
        <br />
        <input type="radio" name="packageSelect" value="Gold Breakfast Package">&nbsp;Gold&nbsp;(lunch; exclusive sponsorship)
        <br />
        <br />
            <input type="radio" name="packageSelect" value="Gold Trade Show Package">&nbsp;Gold&nbsp;(trade&nbsp;show; exclusive sponsorship)
    </fieldset>
    <br />
    <button type="submit">Submit</button>&nbsp;<button type="reset">Reset</button><br />
    

    And here is the PHP script I've written:

    <?php
    
    if(!isset($_POST['submit']))
    {
        echo "error; you need to submit the form!";
    }
    
    $vendorName = $_POST['vendorName'];
    $contactName = $_POST['contactName'];
    $vendorType = $_POST['vendorType'];
    $other1 = $_POST['other1'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $questions = $_POST['questions'];
    $packageSelect = $_POST['packageSelect'];
    
    if (empty($vendorName)||(empty($contactName)||(empty($vendorType)||(empty($email)||(empty($phone)||(empty($packageSelect)) {
        echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
        exit;   
    }
    
    $email_from = 'example@domain.com';
    $email_subject = '2014 SMS Sales Summit - New Vendor Reservation Request';
    $email_body = "You have received a new vendor reservation request for the 2014 SMS Sales Summit from $contactName at $vendorName.\n".
                  "Vendor Type: $vendorType\n".
                  "Other Vendor Type: $other1\n".
                  "Email Address: $email\n".
                  "Phone Number: $phone\n".
                  "Additional Questions: $questions\n".
                  "Sponsorship Level: $packageSelect\n".
    
    $to = 'example@domain.com';
    $headers = "$email_from \r\n";
    $headers .= "Reply-To: $email \r\n";
    
    mail($to,$email_subject,$email_body,$headers);
    header('Location: thank-you.html');
    
    
    
    ?>
    

    I'm pretty sure that I've got everything set up correctly to pull the information submitted into the 'input' fields, but I'm not sure if I've implemented this correctly for the radio buttons and the drop down selector. Any help with this implementation would be most appreciated. Thanks!

    解决方案

    1. add a method to your form as:

      <form action="" method="post" id="vendorInfo"> //its an example

    2. Give name attribute to your all input filed as:

      <input type="text" name="whatever"> //its an example

    then catch these by post method in php

    <?php
    if(isset($_POST['your_submit_name']))
    {
    $input_field=$_POST['your_input_field_name'];
    $to = "somebody@example.com";
    $subject = "your subject";
    $message= "Hello mail!". "\r\n";
    $message.= $input_field."\r\n";
    $headers = "From: webmaster@example.com" . "\r\n" ;
    mail($to,$subject,$message,$headers);
    ?>
    

    这篇关于向电子邮件提交HTML5表单(通过php?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆