如何将多个字段的表单发送到具有多个变量的电子邮件中? [英] How do I send a multiple field form to email with multiple variables?

查看:34
本文介绍了如何将多个字段的表单发送到具有多个变量的电子邮件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了今天的大部分时间和昨天的全部时间,试图使一个简单的,基本的发送到电子邮件的PHP代码正常工作.这是我根据在本网站和其他网站上阅读的许多其他主题进行广泛的研究,检查和编辑之后,尝试将自己整合在一起的代码.

I've spent most of today and all of yesterday just trying to get a simple, basic send-to-email PHP code to work. Here is the code I've tried putting together myself after extensively researching, checking, and editing based on a lot of other threads I've read on this website and on other sites.

   <?php 

$to='dustedpages@gmail.com';
$subject='Commission Inquiry';
$email = $_REQUEST['Email'] ; 
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ; 
$message="Name:  ".$name. "\r\n" . "Email:  " .$email . "\r\n" . "Username:  " .$user . "\r\n" . "Type:  ".$position. "\r\n" . "Add-Ons:  ".$addons. "\r\n" . "Price:  ".$price. "\r\n" . "Brief Description:  ".$briefdesc;


$name=$_POST['FirstName'],['LastName'];
$email=$_POST['Email'];
$user=$_POST['User'];

$position=$_POST['position'];
$addons=$_POST['cat'],['dog'];
$price=$_POST['price'];
$desc=$_POST['briefdesc'];



if($sent) 
{print "Your mail was sent successfully. Please be patient and the artist will contact you soon. Thanks!"; }
else 
{print "We encountered an error sending your mail"; }


?> 

实际上除了基本信息外还有很多表单数据,但是我什至无法显示基本信息.对于它从中提取的html代码部分,这是它的某些样子.

There is actually a LOT more form data than just that basic information, but I cannot even get the basic information to show up. For the portion of html codes it is pulling from, here is some of what it looks like.

<!--NAME-->
        </li>       <li id="li_2" >
        <label class="description" for="element_2">Name </label>
        <span>
        <input onkeypress="return handleEnter(this, event)" id="element_2_1" name="FirstName" class="element text" maxlength="255" size="14" value=""/>
        <label>First</label>
        </span>

        <span>
        <input onkeypress="return handleEnter(this, event)" id="element_2_2" name="LastName" class="element text" maxlength="255" size="18" value=""/>
        <label>Last</label>
        </span>
        <p class="guidelines" id="guide_2"><small>Please fill this in as the name I will see on Paypal.</small></p> 

<!--EMAIL-->

        </li>       <li id="li_1" >
        <label class="description" for="element_1">Email </label>
        <div>
        <input onkeypress="return handleEnter(this, event)" id="element_1" name="Email" class="element text medium" type="text" maxlength="255" value=""/>  
        </div>
        <p class="guidelines" id="guide_1"><small>Your Paypal email</small></p> 



<!--USERNAME-->

        </li>       <li id="li_3" >
        <label class="description" for="element_3">DA/Tumblr Username </label>
        <div>
        <input onkeypress="return handleEnter(this, event)" id="element_3" name="User" class="element text medium" type="text" maxlength="255" value=""/> 
        </div>
        <p class="guidelines" id="guide_3"><small>If you have an account on either Deviantart or Tumblr and wish to be credited in the commission description, please note it here.</small></p> 
        </li>
        <p> 

<!--POSITION TYPE-->

    </li>       <li id="li_26" >
    <label class="description" for="element_26">Comm. Type </label>

    <div>

    <select class="element select medium" id="element_26" name="position"> 

    <option value="" selected="selected"></option>
    <option value="1" >Bust</option>
    <option value="2" >Waist</option>
    <option value="3" >Full-Body</option>

    </select>
    </div>

    <p class="guidelines" id="guide_26">
    <small>Please choose what position you wish for your character(s) to be viewed from. Price will change depending on what type you choose.</small></p> 


<!--ADD ONS-->

    </li>       <li id="li_27" >
    <label class="description" for="element_27" name="addons">Add-Ons </label>

    <span>

    <input name="cat" type="checkbox" onClick="return KeepCount()">
    +1 Character<br>


    <input name="dog" type="checkbox" onClick="return KeepCount()">
    +2 Characters

我有多个字段(例如名和姓),我需要将其作为电子邮件代码中的一个变量,并且我需要能够显示电子邮件中所有已填写的表单字段.此时,我什至无法显示多个变量.

I have multiple fields (such as the First and Last Name) that I need to be one single variable in the email code, and I need to be able to display all of the filled out form fields in an email. I can't even get more than one variable to show up at this point.

表单本身还包括选择,复选框,文本区域和图像上传.我什至还没有达到这一点-我只是想使一些基本信息立即显示出来.尽管我以前使用过HTML和Javascript,但我对HTML和Javascript非常熟悉.某些表单数据也与HTML在同一页上的Javascript代码中使用.实际的PHP数据在我的表单从中提取的单独文件中.

Also the form itself includes selects, checkboxes, textareas, and image uploads. I haven't even gotten to that point - I'm just trying to make some of the basic information show up right now. I'm very familiar with HTML and Javascript, just not so much PHP, though I've worked with it before. Some of the form data is used in Javascript code on the same page as the HTML, also. The actual PHP data is on a separate file that my form pulls from.

推荐答案

我认为正在发生的事情是您在变量没有所需值之前就尝试使用它们.尝试以下类似的方法,让我知道如何进行.

I think what's happening is you're attempting to use variables before they have the value you would like. Try something like the following and let me know how it goes.

<?php

$to = 'dustedpages@gmail.com';
$subject = 'Commission Inquiry';
$headers = "From: $email";

$fname = $_POST['FirstName'];
$lname = $_POST['LastName'];
$email = $_POST['Email'];
$user = $_POST['User'];
$position = "CHANGE-ME";
$addons = "CHANGE-ME";
$price = "CHANGE-ME";
$briefdesc = "CHANGE-ME";

$message = "Name: ".$fname.", ".$lname."\r\n";
$message .= "Email: $email \r\n";
$message .= "Username: $user \r\n";
$message .= "Type: $position \r\n";
$message .= "Add-Ons: $addons \r\n";
$message .= "Price: $price \r\n";
$message .= "Brief Description: $briefdesc \r\n";

$sent = mail($to, $subject, $message, $headers);

if($sent) {
    echo "Success";
}
else {
    echo "Failure";
}
?>

这篇关于如何将多个字段的表单发送到具有多个变量的电子邮件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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