2014-02-05 36 views
0

我已经使用了同样的形式多次,但这个特殊的场合似乎并没有发送任何电子邮件,也没有提供任何错误信息或确认信息。联系表格不提供错误,确认或电子邮件

输出:print_r($ _ POST);从测试刚才是以下内容:

Array([Name] => test name [Email] => [email protected] [Company] => example company [Position] => ceo [Captcha ] => 1)

所以表单正确地抓取所有细节并试图传递它们,但没有电子邮件或确认/错误(s)。

PHP/HTML

<?php 
        if (count($error)>=1) { 
         foreach($error as $one_error) { 
          echo '<h3>'.$one_error.'</h3>'; 
          echo '<div class="clear"></div>'; 
         } 
        } 
        if ($message_sent) { 
         echo '<h2>Thank you for your request. We will be in touch soon!</h2>'; 
         echo '<hr class="hr" />'; 
        } 
       ?> 

       <form action="index.php" method="POST"> 
       <span> 
        <label><strong>Name</strong></label><br /> 
        <input type="text" name="Name" placeholder="Name" value="<?=$Name;?>" required /> 
       </span> 
       <span> 
        <label><strong>Your Email Address</strong></label><br /> 
        <input type="text" name="Email" placeholder="Email Address" value="<?=$Email;?>" required /> 
       </span> 
      <br /><br /> 
       <span> 
        <label><strong>Company</strong></label><br /> 
        <input type="text" name="Company" placeholder="Company" value="<?=$Company;?>" required /> 
       </span> 
       <span> 
        <label><strong>Position</strong></label><br /> 
        <input type="text" name="Position" placeholder="Company Position" value="<?=$Position;?>" required /> 
       </span> 
      <br /> <br /> 
       <label><strong>Captcha</strong></label><br /> 
       <img src="<?php HTTP_HOST ?>/Contact/answer.php"> 
       <input type="text" placeholder="Enter Sum Calculation" name="Captcha" value="<?=$Captcha;?>" required /> 
      <div class="clear"></div><br /> 
       <input type="submit" value="Send Enquiry" /> 
       </form> 

PHP(内同一index.php文件的)

<?php 
    session_start(); 
print_r($_POST); 
// print_r($_SESSION['code']); 
function isValidInetAddress($data, $strict = false) { 
    $regex = $strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i'; 
    if (preg_match($regex, trim($data), $matches)) { 
     return array($matches[1], $matches[2]); 
    } else { 
     return false; 
    } 
} 
$Name = '';$Email = '';$Company = '';$Position = '';$Captcha = ''; 

if (isset($_POST)&&(isset($_POST['Submit'])&&(strlen($_POST['Submit'])>1))) { 
    $error = array(); 
    if (isset($_POST['Name'])&&(strlen($_POST['Name'])>1)) { 
     $Name = $_POST['Name']; 
    } else { 
     $error[]='Name is empty'; 
    } 
    if (isset($_POST['Email'])&&(strlen($_POST['Email'])>1)) { 
     $Email = $_POST['Email']; 
    } else { 
     $error[]='Email is empty'; 
    } 
    if (isset($_POST['Company'])&&(strlen($_POST['Company'])>1)) { 
     $Company = $_POST['Company']; 
    } else { 
     $error[]='Company is empty'; 
    } 
    if (isset($_POST['Position'])&&(strlen($_POST['Position'])>1)) { 
     $Position = $_POST['Position']; 
    } else { 
     $error[]='Position is empty'; 
    } 
    if (isset($_POST['Captcha'])&&($_POST['Captcha']==$_SESSION['code'])) { 
    } else { 
     $error[]='Captcha is wrong'; 
    } 
    if (count($error)<1) { 
     $headers = 'From: [email protected]' . "\r\n" . 
      'Reply-To: [email protected]' . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 

     $message ='New DiSC Profile Request'."\r\n"; 
     $message .= 'Name: '.$Name."\r\n"; 
     $message .= 'Email: '.$Email."\r\n"; 
     $message .= 'Company: '.$Company."\r\n"; 
     $message .= 'Position: '.$Position."\r\n"; 


     mail('[email protected]', 'New DiSC Profile Request', $message, $headers); 
     // mail('[email protected]', 'New Enquiry from Urban Country', $message, $headers); 
     unset($Name);unset($Email);unset($Company);unset($Position); 
     $message_sent = TRUE; 
    } 
} 
?> 

回答

1

变化形式提交按钮,并给它一个名称

<input type="submit" value="Send Enquiry" /> 

<input type="submit" value="Send Enquiry" name="Submit"/> 
+0

噢!谢谢,现在工作正常。 – JordanC26

+0

但在这种情况下,它应该是名称=“提交”,不应该吗? –

+0

@MarcelBalzer良好的捕获我有一个错字:(只是修复它的答案。 –

0

你需要在按钮上有name =“”;

<input type="submit" value="Send Enquiry" name="submit" /> 

如果php在同一页面上,您也不需要执行action =“index.php”;

<form action="" method="POST"> 

而且你不需要

if (isset($_POST)&&(isset($_POST['Submit'])&&(strlen($_POST['Submit'])>1))) { 

用途:if (isset($_POST['submit'])===true) {