使用PHP将价值数据传递到电子邮件的教程 [英] Tutorials for passing value data to email with PHP

查看:69
本文介绍了使用PHP将价值数据传递到电子邮件的教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个html表单,用户必须在其中指定他喜欢订购的产品,并根据他的回答出现其他输入字段.我已经为此使用了一些JavaScript.但是,现在我想记录用户输入的数据,以通过php传递给电子邮件.一般而言,我对php和脚本的了解很少(让我们一无所获),但是我确实找到了一些教程和模板.唯一的事情是,它们似乎都略有不同并且特定于表单(主要是联系表单).而且,如果我密切关注它们,效果很好,只是当我想进行一些自定义时,我似乎迷失了.

I have built a html form in which a user has to specify which product he likes to order and depending on his answer other input fields arise. I have used some javascript for that. But now i want to data the user enters to be passed on to email via php. I know very little of php and scripting in general (let's say about nothing) but i did find some tutorials and templates on it. The only thing is that they all seem slightly different and specific to a form (mostly contact forms). And if i follow them closely it works fine, it's just that when i want to customize a little i seem to get terribly lost.

我之前已经发布了此内容(

I have posted this before (Can i post data from a select drop down to email using PHP?) and have gotten some answers. It's just that i didn't formulate my initial problem well enough and edited it afterwards, but i don't know if that's the way to go on this forum. So i posted a new question (sorry if that's overkill, i'm pretty new to all of this). This is my html:

            <form method="post" name="contact_form" action="contact.php">                       
                <div class="form-div1">
                    <label for="profile" class="label1">Select your profile</label>
                    <br>
                    <select id="user-type" class="selectlist">
                        <option value="option1">I'm a first-time user</option>
                        <option value="option2">I would like to renew or upgrade</option>
                    </select>
                </div>

                <div class="form-div2">
                    <label for="SEN" class="label2">SEN</label>
                    <br>
                    <input type "text" name="input1" class="input1">
                </div>

                <div class="form-div3">
                    <label for="email" class="label3">Email Address</label>
                    <br>
                    <input type "text" name="input2" class="input2">
                </div>

                <div class="form-div4">
                    <label for="product_choice" class="label4" name="select_menu">Select your product</label>
                    <br>
                    <select id="product" class="selectlist">
                        <option value="option1">JIRA</option>
                        <option value="option2">Confluence</option>
                        <option value="option3">JIRA Service Desk</option>
                        <option value="option4">Stash</option>

                        <option value="option5">Other</option>
                    </select>
                </div>

                <div class="form-div42">
                    <label for="product" class="label42">Specify your product</label>
                    <br>
                    <input type "text" name="input2" class="input2">
                </div>

                <div class="form-div5">
                    <label for="license_choice" class="label5">Select your license</label>
                    <br>
                     <select id="select" class="selectlist">
                        <option value="option1">25 users</option>
                        <option value="option2">50 users</option>
                        <option value="option3">100 users</option>
                    </select>
                </div>

                <div class="input_box_atlassian">
                    <input type="submit" name="submit" value="Submit" class="submit-button-atl" />
                </div>
            </form>

现在,我想构建可运行的php,以便可以将数据传递到电子邮件中.有人可以向我指出正确的方向,还是可以向我展示一些更紧密地解决这个问题的教程.

Now i want to build working php so i can pass the data to an email. Can somebody point me in the right direction or preferably show me some tutorials that tackle this issue more closely.

推荐答案

我没有进行任何验证,请尝试在客户端&服务器端验证以及代码 如下更改HTML

I havent dont any validation, try client side & server side validation along with code Change the HTML as below

 <form method="post" name="contact_form" action="contact.php">                       
                <div class="form-div1">
                    <label for="profile" class="label1">Select your profile</label>
                    <br>
                    <select id="user_type" name="user_type" class="selectlist">
                        <option value="I'm a first-time user">I'm a first-time user</option>
                        <option value="I would like to renew or upgrade">I would like to renew or upgrade</option>
                    </select>
                </div>

                <div class="form-div2">
                    <label for="SEN" class="label2">SEN</label>
                    <br>
                    <input type "text" name="SEN" class="SEN">
                </div>

                <div class="form-div3">
                    <label for="email" class="label3">Email Address</label>
                    <br>
                    <input type "text" name="email" class="email">
                </div>

                <div class="form-div4">
                    <label for="product_choice" class="label4" name="select_menu">Select your product</label>
                    <br>
                    <select id="product" name="product" class="selectlist">
                        <option value="JIRA">JIRA</option>
                        <option value="Confluence">Confluence</option>
                        <option value="JIRA Service Desk">JIRA Service Desk</option>
                        <option value="Stash">Stash</option>
                        <option value="Other">Other</option>
                    </select>
                </div>

                <div class="form-div42">
                    <label for="product" class="label42">Specify your product</label>
                    <br>
                    <input type "text" name="product_specify" id="product_specify" class="input2">
                </div>

                <div class="form-div5">
                    <label for="license_choice" class="label5">Select your license</label>
                    <br>
                     <select id="license_choice" name="license_choice" class="selectlist">
                        <option value="25">25 users</option>
                        <option value="50">50 users</option>
                        <option value="100">100 users</option>
                    </select>
                </div>

                <div class="input_box_atlassian">
                    <input type="submit" name="submit" value="Submit" class="submit-button-atl" />
                </div>
            </form>

创建另一个名为contact.php&的PHP文件.粘贴以下代码.

And make another PHP file by the name contact.php & paste the below code.

<?php
if($_REQUEST['submit']=='Submit'){
    $user_type=$_REQUEST['user_type'];
    $sen=$_REQUEST['SEN'];
    $email=$_REQUEST['email'];
    $product=$_REQUEST['product'];
    $product_specify=$_REQUEST['product_specify'];
    $license_choice=$_REQUEST['license_choice'];

    $to      = 'nobody@example.com'; //to whom the email have to besnd
    $message = "User Type: $user_type \n Sen: $sen \n Email: $email \n Product: $product \n Product Specified: $product_specify \n License: $license_choice"; //content of the email
    $subject = 'hello';  //shown as subject of the email
    $headers = 'From: webmaster@example.com' . "\r\n" . //eamil header information
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    if(mail($to, $subject, $message, $headers)){
    echo "Mail Sucessfully Sent";
    } else {
    echo "Something went wrong";
    }
}
?>

这将从HTML&表格中获取内容.通过电子邮件发送其内容,但是只有在正确配置了电子邮件服务器的情况下

This will get the content from the form HTML & email its contents, however only if the email server is configured correctly

这篇关于使用PHP将价值数据传递到电子邮件的教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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