0

我今天和昨天的大部分时间都在试图让一个简单的、基本的发送到电子邮件的 PHP 代码工作。这是我根据我在本网站和其他网站上阅读的许多其他线程进行的广泛研究、检查和编辑后自己尝试整理的代码。

   <?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 代码部分,这里是它的一些样子。

<!--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

我有多个字段(例如名字和姓氏),我需要成为电子邮件代码中的一个变量,并且我需要能够在电子邮件中显示所有填写的表单字段。在这一点上,我什至无法显示一个以上的变量。

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

4

1 回答 1

2

我认为正在发生的事情是您试图在变量具有您想要的值之前使用它们。尝试以下类似的方法,让我知道它是如何进行的。

<?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";
}
?>
于 2013-09-19T01:56:25.157 回答