javascript - PHP 通过电子邮件将选定的变量发送给用户

标签 javascript php mysql email

我想将选定的对象发送到电子邮件地址。

这是一个演示: http://jsfiddle.net/62g3s8sz/

我知道可以用 PHP 发送电子邮件,我尝试了很多方法,但都没有成功。

电子邮件需要与所选项目相对应。

因此,如果选择配备 AMD FM2 A6-6400K 双核 3,9GHz 的 Cooler Master K-380,我需要它列出这些项目

机箱:酷冷至尊 K-380:价格 处理器:AMD FM2 A6-6400K 双核 3.9GHz:价格

然后将其发送到该人登录时使用的电子邮件地址。 我知道 $loggedInUser->email 将显示电子邮件地址。

如果有人知道如何将电子邮件中的所有这些信息发送给登录者,那就太好了。

HTML:

<script type="text/javascript" src="js/formcalc.js"></script>

<form method="POST" name="contactform" action="contact-form.php" id="computerform">
    <div>
        <div class="cont_order">
            <fieldset>
                <legend></legend>
                <label>Case</label>
                <br>
                <label class='radiolabel'>
                    <input checked="checked" type="radio" name="selectedcase" value="2001" onclick="calculateTotal()" />Cooler Master K-350 - ($10)</label>
                <br/>
                <label class='radiolabel'>
                    <input type="radio" name="selectedcase" value="2002" onclick="calculateTotal()" />Cooler Master K-380 - ($20)</label>
                <br/>
                <br/>
                <label>Processor</label>
                <br>
                <label class='radiolabel'>
                    <input checked="checked" type="radio" name="selectedprocessor" value="3001" onclick="calculateTotal()" />AMD FM2 A4-5300 Dual Core 3,4GHz - ($10)</label>
                <br/>
                <label class='radiolabel'>
                    <input type="radio" name="selectedprocessor" value="3002" onclick="calculateTotal()" />AMD FM2 A6-6400K Dual Core 3,9GHz - ($20)</label>
                <br/>
                <br/>
                <label>Totale price</label>
                <div class="total">
                    <div id="case"></div>
                    <div id="totalPrice"></div>
                </div>
                <br>
            </fieldset>
        </div>
        <input type='submit' id='submit' value='Bestel' onclick="calculateTotal()" />
    </div>
</form>

JavaScript 代码

 var case_prices = new Array();
 case_prices["2001"]=10;
 case_prices["2002"]=20;

 var processor_prices = new Array();
 processor_prices["3001"]=10;
 processor_prices["3002"]=20;




window.onload = function() 
{
    calculateTotal();
}

// getCasePrice() finds the price based on the selected case
// Here, we need to take user's the selection from radio button selection
function getCasePrice()
{  
    var casePrice=0;
    //Get a reference to the form id="computerform"
    var theForm = document.forms["computerform"];
    //Get a reference to the case the user Chooses name=selectedcase":
    var selectedCase = theForm.elements["selectedcase"];
    //We loop through each radio buttons
    for(var i = 0; i < selectedCase.length; i++)
    {
        //if the radio button is checked
        if(selectedCase[i].checked)
        {
            //we set cakeSizePrice to the value of the selected radio button
            //i.e. if the user choose the 8" cake we set it to 25
            //by using the cake_prices array
            //We get the selected Items value
            //For example cake_prices["Round8".value]"
            casePrice = case_prices[selectedCase[i].value];
            //If we get a match then we break out of this loop
            //No reason to continue if we get a match
            break;
        }
    }
    //We return the cakeSizePrice
    return casePrice;
}


// getCasePrice() finds the price based on the selected case
// Here, we need to take user's the selection from radio button selection
function getProcessorPrice()
{  
    var processorPrice=0;
    //Get a reference to the form id="computerform"
    var theForm = document.forms["computerform"];
    //Get a reference to the cake the user Chooses name=selectedprocessor":
    var selectedProcessor = theForm.elements["selectedprocessor"];
    //We loop through each radio buttons
    for(var i = 0; i < selectedProcessor.length; i++)
    {
        //if the radio button is checked
        if(selectedProcessor[i].checked)
        {
            //we set cakeSizePrice to the value of the selected radio button
            //i.e. if the user choose the 8" cake we set it to 25
            //by using the cake_prices array
            //We get the selected Items value
            //For example cake_prices["Round8".value]"
            processorPrice = processor_prices[selectedProcessor[i].value];
            //If we get a match then we break out of this loop
            //No reason to continue if we get a match
            break;
        }
    }
    //We return the cakeSizePrice
    return processorPrice;
}


function calculateTotal()
{
    //Here we get the total price by calling our function
    //Each function returns a number so by calling them we add the values they return together
    var computerPrice = getCasePrice() + getProcessorPrice() + getCoolerPrice() + getMotherboardPrice();

    //display the result
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='block';
    divobj.innerHTML = "Totale prijs: &euro;"+computerPrice ;
}

谢谢:)

最佳答案

我不喜欢只粘贴答案的链接,但是......

http://php.net/manual/en/function.mail.php

所以你所需要的就是这样的

$content = "..write it here yadda yadda whatever is your mail content ..";
$ok = mail($mailTo,"Hello, this is the mail subject",$content);

请注意,这将发送纯邮件,还有一些额外的步骤来制作 HTML 邮件,所有这些都包含在上面的链接中。祝你好运

几点提醒:除非您安装了邮件守护程序并使用 PHP,否则它可能无法在您的本地计算机上运行,​​并且您可能需要根据 PHP 的安装方式调整该 mail() 函数的最后一个参数。

关于javascript - PHP 通过电子邮件将选定的变量发送给用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26433358/

相关文章:

javascript - 谷歌地图/gmap3 - 绘制从用户地理位置到已知目的地的路线 - 需要帮助

javascript - Canvas 的砌体布局

javascript - 输入值未在 React 中更新

php - 在 angularjs 中定义路由后,注册表单不起作用

php - 给我关于匹配人的算法的建议

mysql - 如何在 mysql 中存储客户数据(2 表 vs 1 表)

javascript - Dojo:获取对 dijit.form.Select 中单击项的访问权限?

php - 关于静态页面的 CodeIgniter 教程

MySQL 按时间过滤数据库查询并查找重复项

php - 如何动态显示一个页面执行了多少个mysql查询?