【问题标题】:Not getting the values in to mail没有将值发送到邮件
【发布时间】:2015-02-23 05:41:35
【问题描述】:

我使用 java 脚本在表单中创建了一个动态下拉列表添加行。以我的形式,我没有从中获得价值。如果我们填写 3 行,只得到一个行值来发送邮件。

我已经更改了现在获取值但无法提交到电子邮件的代码 给我解决方案我该怎么做

<?php
	
	
	echo $_POST['optionval'][0];
	echo $_POST['optionoth'][0];			
	echo $_POST['date'][0];
	echo $_POST['Num'][0];
	echo $_POST['num'][0];
	echo $_POST['optionval'][2];
	echo $_POST['optionoth'][3];			
	echo $_POST['date'][4];
	echo $_POST['Num'][5];
	echo $_POST['num'][6];
	echo $_POST['optionval'][2];
	echo $_POST['optionoth'][2];			
	echo $_POST['date'][2];
	echo $_POST['Num'][2];
	echo $_POST['num'][2];
	
	$optionval= $_POST['optionval']; // required 
		$optionoth= $_POST['optionoth']; // required 
			$date= $_POST['date']; // required 
		$Num= $_POST['Num']; // required 
		$num= $_POST['num']; // required 


	 $email_from = '******@gmail.com';//<== update the email address
	$email_subject = "New Order submission";  
	$message = '<html><body>';
				$message .= '<img src="*******" alt="New Appointment" />';
				$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
				
				$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['optionval']) . "</td></tr>";
				$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['optionoth']) . "</td></tr>";
					$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['date']) . "</td></tr>";
				$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['Num']) . "</td></tr>";
	$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['num']) . "</td></tr>";
				
				$message .= "</table>";
				$message .= "</body></html>";
	
	
	
	$to = "******@gmail.com";//<== update the email address
	$headers = "From: $email_from \r\n";
	//$headers .= "Reply-To: $visitor_email \r\n";
	$headers .= "CC: *******@gmail.com \r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	
	//Send the email!
	mail($to,$email_subject,$message,$headers);
	//done. redirect to thank-you page.
	if(!isset($_POST['submit']))
	{
		//This page should not be accessed directly. Need to submit the form.
		//echo "error; you need to submit the form!";
	}
	header( 'Location:www.google.com' );
	
	// Function to validate against any email injection attempts
	function IsInjected($str)
	{
	  $injections = array('(\n+)',
				  '(\r+)',
				  '(\t+)',
				  '(%0A+)',
				  '(%0D+)',
				  '(%08+)',
				  '(%09+)'
				  );
	  $inject = join('|', $injections);
	  $inject = "/$inject/i";
	  if(preg_match($inject,$str))
		{
		return true;
	  }
	  else
		{
		return false;
	  }
	}
	
	
	?>
<table border="0" cellpadding="0" cellspacing="0">
            <thead>
                  <tr>
                    <td>Option</td>
                    <td>Text</td>
                    <td>Num</td>
                   <td>No</td>
                  </tr>             
        </thead>
           <tbody class="row">
           		<tr class="row-nt">
                	<td>
                    <select name="optionval[]" class="ceventselect" required="">
                          <option value="option-1" selected="selected">option-1</option>
                          <option value="option-2">option-2</option>
                          <option value="option-3">option-3</option>
                          <option value="option-4">option-4</option>
                         
                      </select>                        
                        <input name="optionoth[]" type="text" class="optionother" style="display: none;margin-top:10px;">
                  </td>
                    <td><input name="date[]" type="text" class="date" required=""></td>
                    <td>
                    	<select name="Num[]" class="form_field_box4 valid" required="">
                          <option value="Num-1" selected="selected">Num-1</option>
                          <option value="Num-2">Num-2</option>
                          <option value="Num-3">Num-3</option>
                          <option value="Num-4">Num-4</option>
                          
                      </select>
                    </td>
                  
                    <td>
                    	<input name="num[]" type="number" class="boxnum"  required="">
                    
                       
                  </td>
                </tr>
           </tbody>
      </table>
        <button class="add-new-evt">Add Row</button>
        

         <input type="submit" value="Submit">

    </div>
</form>  

【问题讨论】:

    标签: javascript php html email post


    【解决方案1】:

    如果您将表单元素的名称从 xyz 更改为 xyz[],那么您应该为每个包含您的值的名称获取一个数组。

    例如

    <input name="date[]" type="text" class="date" value="2014-12-25" required="">
    <input name="date[]" type="text" class="date" value="2014-12-24" required="">
    

    然后应该看起来像:

    echo $_POST['date'][0]; //2014-12-25 
    echo $_POST['date'][1]; //2014-12-24 
    

    如果没有[],每一行都具有相同的名称,则只会提交最后一行的值。

    【讨论】:

    • 很好的解释。这也适用于上传多个文件。使用file[] 作为inputs 或formdata 条目的名称
    猜你喜欢
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 2016-10-10
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多