邮件来自表单

时间:2016-02-05 07:33:15

标签: php html email

我有三个档案。索引,是我的形式。 checkout.php,其中包含所选项目的细分,以及包含一些信息的表单。我的上一个文件是email.php,其中包含通过电子邮件发送结果的代码。我试图通过电子邮件发送故障部分,以便我知道那个人想要什么。

<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Mid-Night Designs Quote</title>
	
    <!--Required-->
	<script src="js-assets/jquery-1.11.2.min.js"></script>
	<script src="js-assets/cost_calculator.js"></script>
    <!--/Required-->
    
	<link href='default-styles.css' type="text/css" rel="stylesheet">
	<style type="text/css">
	body,td,th {
	color: rgba(0,0,0,1);
}
    </style>
</head>
<body>
    
<!--Quick Reference

- Each row should have these data tags: 'data-row', 'data-value'
- Each row required the class 'cost_calc_calculate'
- Optional data tags: 'data-show', 'data-id', 'data-select'
- Optional classes: 'single'

- 'data-row' is the individual row, you can have multiple items attached to the data row, think of it as a group or a section for your pricing.

- 'data-value' is the cost of the item they have selected, this is used to add to your calculated cost. You can leave 'data-value' blank if you like, but when they click the item it will revert to the default message you set in the 'cost_calculator.js' file. If you want the value to be 0, just simply put "0" instead of nothing.

-'data-show' will show a row that you have hidden with the 'cost_calc_hide' class, this is good to use when you only want a certain row to show for a certain option.
Explained: If you put 'data-show="2"'. This will show any row with the value of "2" on the 'data-row'

-'data-id' should be unique to every item, don't repeat it.

-'data-select' is used to automatically select an item with the 'data-id' value you enter.

-The class 'single' will only let one option in that row be choosen at a time. If this class is not applied, the user will be able to select multple options in a row.

You can see a full working example below. Enjoy and I hope you enjoy this simple, yet powerful plugin.

/Quick Reference-->
    
<div class="container clearfix">
    
    <h1>Mid-Night Designs</h1>
    
    <p>
       
       <h3><a  href='http://mid-nightdesigns.com'>Back to Mid-Night Designs</a></h3>
    </p><center>
    *This quote calculator isn't 100% accurate and may vary*
    <p></p></center>
    
    <form method="post">
    <h3>Step 1: Select A Website Style</h3>
    <!-- Price Button(data-value is the price assigned to the button)-->
        <!--Row 1-->
		<!--This is a default price that'll always be applied-->
		<input type="button" class="cost_calc_row-1 single cost_calc_calculate " value="Simple Website" 
               data-row='1' 
               data-id='1' 
               data-select='2'
               data-value="100">
		<!--/-->
	
		<input type="button" class="cost_calc_row-1 cost_calc_calculate single " value="Advanced Website" 
               data-row='1' 
               data-select='2'
               data-value="250">
               
        <input type="button" class="cost_calc_row-1 cost_calc_calculate single " value="eCommerce" 
               data-row='1' 
               data-select='2'
               data-value="320">     
               
		<input type="button" class="cost_calc_row-1 cost_calc_calculate single " value="Blog" 
               data-row='1' 
               data-select='2'
               data-value="420">
        
        <h3>Step 2: How Many Static Pages Do You Need?</h3>
		<!--Row 2-->
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="1 Page" 
               data-row='2' 
               data-select='1' 
               data-id='2'
               data-value="60">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="2 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="80">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="3 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="100">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="4 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="120">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="5 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="140">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="6 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="160">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="7 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="180">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="8 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="200">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="9 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="220">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="10 Pages" 
               data-row='2' 
               data-select='1' 
               data-value="250">

		<!--If the data-value is equal to nothing, you'll be shown the default "more" field-->
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="10-20 Pages" 
               data-row='2' 
               data-value="410">
    
		<input type="button" class="cost_calc_row-2 cost_calc_calculate single " value="Not Sure?" 
               data-row='2' 
               data-value="none">
		<!--/-->
  <h3>Step 3: How Many Dynamic Pages Do You Need? (Database cost has been included in every page)</h3>
	    <p>
		   <!--Row 3-->
		   <input type="button" class="cost_calc_row-3 cost_calc_calculate single " value="1 Dynamic Page & Database" 
               data-row='3' 
               data-select='1' 
               data-id='5'
               data-value="400">
		   
		   <input type="button" class="cost_calc_row-3 cost_calc_calculate single " value="2 Dynamic Pages" 
               data-row='3' 
               data-select='1' 
               data-value="400">
		   
		   <input type="button" class="cost_calc_row-3 cost_calc_calculate single " value="3 Dynamic Pages" 
               data-row='3' 
               data-select='1' 
               data-value="400">
  </p>
	    <p>
	      
          <h3>Step 4: Choose A Content Management System</h3>
	    <p>
		   <!--Row 3-->
		   <input type="button" class="cost_calc_row-3 cost_calc_calculate single " value="Admin CMS" 
               data-row='4' 
               data-select='1' 
               data-id='5'
               data-value="550">
		   
		   <input type="button" class="cost_calc_row-3 cost_calc_calculate single " value="Basic In-Browser Editing" 
               data-row='4' 
               data-select='1' 
               data-value="0">
		   
		   <input type="button" class="cost_calc_row-3 cost_calc_calculate single " value="We Manage" 
               data-row='4' 
               data-select='1' 
               data-value="50/Mo">
  </p>
	    <p>
        
        
        <h3>Step 5: Choose A Desired Time Frame</h3>
	    <p>
		   <!--Row 3-->
		   <input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Durations" 
               data-row='4' 
               data-value="0" 
               data-show="5">
  </p>
	    <p>
          
           <!--Row 4, this row is hidden until "Quick turn around" is clicked, note the use of 'data-show' on that item above-->
		<input type="button" class="cost_calc_row-4 cost_calc_calculate single cost_calc_hide" value="5 Days" 
               data-row='5' 
               data-value="999">
    
		<input type="button" class="cost_calc_row-4 cost_calc_calculate single cost_calc_hide" value="7 Days" 
               data-row='5' 
               data-value="599">
    
		<input type="button" class="cost_calc_row-4 cost_calc_calculate single cost_calc_hide" value="2 Weeks" 
               data-row='5' 
               data-value="299">
    
		<input type="button" class="cost_calc_row-4 cost_calc_calculate single cost_calc_hide" value="5 Weeks" 
               data-row='5' 
               data-value="0">

          
	      <!--/--></p>
	    <h3>Step 6: Any Additional Services?</h3>
		<!--Row 4-->
		<input type="button" class="cost_calc_row-4 cost_calc_calculate " value="Search Engine Optimization" 
               data-row='6' 
               data-value="250">
    
		<input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Mobile & Tablet Design" 
               data-row='6' 
               data-value="130">
    
			<input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Email Address (1)" 
               data-row='6' 
               data-value="60/Yr">
                                      
        <input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Payment Integration" 
               data-row='6' 
               data-value="20">
               
               <input type="button" class="cost_calc_row-4 cost_calc_calculate " value="Advertisements(2)" 
               data-row='6' 
               data-value="10">
    
		<input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Search Box" 
               data-row='6' 
               data-value="50">
    
			<input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="User Registration" 
               data-row='6' 
               data-value="200">
                                      
        <input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Forum" 
               data-row='6' 
               data-value="260">
                      
                      
        <input type="button" class="cost_calc_row-4 cost_calc_calculate " value="Social Media Links" 
               data-row='6' 
               data-value="0">
    
		<input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Multimedia" 
               data-row='6' 
               data-value="25">
    
			<input type="button"  class="cost_calc_row-4 cost_calc_calculate " value="Forms, Surveys, And Polls" 
               data-row='6' 
               data-value="30">
                                  
        </form>                                  
	<!--/-->
 
    
       
	<!--Clear Calculations-->
    <br>
  <div id='cost_calc_clear_calculation' class="hover">Clear selections</div>
    
	<!--Total and breakdown-->
    <div id="cost_calc_breakdown_container" class="clearfix">
        <p class="cost_calc_heading">
        Total cost:<br />
        </p>
        <p id="cost_calc_total_cost">
        0.00<br />
        </p>
        
        <div id="cost_calc_breakdown" class="clearfix">
        </div>
        
		<!--The form that the data is applied to.-->
        <form action="checkout.php" method="post">
			
			<!--Data applied to these field-->
            <textarea id='cost_calc_custom-data' name="cost_calc_cost_data"></textarea>
            <input type="hidden" id='cost_calc_price' value="" name="cost_calc_price">
			<!--/-->
			
            <input type="submit" class="cost_calc_button" value="Start Now!">
        </form>
    </div>
    
</div>

</body>
</html>

<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Getting Started</title>
	
    <!--Validator (optional)-->
	<script src="js-assets/jquery-1.11.2.min.js"></script>
    <script src="js-assets/simple_validate.js"></script>
    
    <script>
    $(document).ready(function() {
        simple_form_validator (
        'This field is required.', 					//Standard input message (.validate)
        'Your email address is required.',  		//Email input message (.validate_email)
        'Your phone number is required.', 			//Phone number message (.validate_phone)
        'Please select an answer.', 				//Radio box message (.validate_radio)
        'Please accept the terms and condtions.',   //Checkbox message (.validate_checkbox)
        '10', 										//Minimum amount of digitals required for phone number
        '12' 										//Maximum amount of digitals required for phone number

        //Please note, to style the required messages, just add your CSS to the class "validate_form_message".
        );
    });
    </script>
    <!--/Validator-->
    
	<link href='default-styles.css' type="text/css" rel="stylesheet">
    
</head>
<body>

<?php 
    //Price
    $full_cost = $_POST['cost_calc_price'];

    //Build breakdown
    $breakdown = $_POST['cost_calc_cost_data'];
    $breakdown = str_replace('d1','<p class="cost_calc_item_name">',$breakdown);
    $breakdown = str_replace('d2','</p>',$breakdown);
    $breakdown = str_replace('d3','<p class="cost_calc_item_price">&#36;',$breakdown);
    $breakdown = str_replace('d4','</p>',$breakdown);

    //Build description
    $description = $_POST['cost_calc_cost_data'];
    $description = str_replace('d1','',$description);
    $description = str_replace('d2','',$description);
    $description = str_replace('d3','- ',$description);
    $description = str_replace('d4',' | ',$description);
?>

<div class='cost_calc_quote_summary clearfix'>
    <h2>Cost Breakdown</h2>
    <?php echo $breakdown; ?>
    <div class='cost_calc_breakdown_total'>Total: &#36;<?php echo $full_cost; ?></div>
</div>

<div class='cost_calc_checkout_form clearfix'>
<form method="post" name="formdata" action="email.php">
    <h2>Information</h2>
        
            <label>
                Email Address
                <input class="SV_validate_email" type="text" NAME="email" placeholder="Email Address">
            </label>

            <label>
                First Name
                <input class="SV_validate" type="text" NAME="first_name" placeholder="First Name">
            </label>

            <label>
                Last Name
                <input class="SV_validate" type="text" NAME="last_name" placeholder="Last Name">
            </label>

            <label>
                Phone Number
                <input class="SV_validate_phone" NAME="phone" type="text" placeholder="Phone Number">
            </label>
             <input type="submit" NAME="submit" value="PURCHASE">
        </div>
    </form>
    <!--End Form-->
</div>
    
</body>
</html>

<?php 
if(isset($_POST['submit'])){
    $to = ""; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
	$phonenumber = $_POST['phone'];
    $subject = "Quote Submission from " . $first_name. $last_name. $phonenumber;
    $subject2 = "Mid-Night Designs Quote Results for" . $first_name;
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST[''];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

1 个答案:

答案 0 :(得分:0)

您必须将表单中的所有数据放到PHP邮件函数的字符串中(字符串可以包含明文或HTML格式的邮件正文)

例如:

checkout.php:
....
count value from index.html form into $counted_value
....
<form.....
....
<input type="hidden" name="countedvalue" value="<?php echo $counted_value;?>"
</form>

email.php:
$message = 'User posted: \n'.
    'email: '.$_POST['email'].
    ', first name: '.$_POST['first_name'].
    ', last name: '.$_POST['last_name'].
    ', phone: '.$_POST['phone'].
    ', value: '.$_POST['countedvalue'];
mail($to, $subj, $message);