我多次使用过同样的表格但是这个特殊的场合似乎并没有发送任何电子邮件,也没有向我提供任何错误信息或确认。
输出:print_r($ _ POST);刚才的测试如下:
数组([名称] =>测试名称[电子邮件] => test@test.com [公司] =>示例公司[位置] =>首席执行官[Captcha] => 1)
因此表单正确地抓取所有细节并尝试传递它们,但没有电子邮件或确认/错误。
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: jordan@gmail.com' . "\r\n" .
'Reply-To: jordan@gmail.com' . "\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('jordan@gmail.com', 'New DiSC Profile Request', $message, $headers);
// mail('galin@mangcreative.com', 'New Enquiry from Urban Country', $message, $headers);
unset($Name);unset($Email);unset($Company);unset($Position);
$message_sent = TRUE;
}
}
?>
答案 0 :(得分:1)
更改表单提交按钮并为其命名
<input type="submit" value="Send Enquiry" />
到
<input type="submit" value="Send Enquiry" name="Submit"/>
答案 1 :(得分: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) {