我不知道为什么它不会发送它只是回声这个消息
糟糕..似乎有技术错误我们真的很抱歉,请稍后再检查< / p>
我不知道问题可能是我忽略了
你能不能告诉我我错了。
如果您需要HTML代码,请告诉我
如何改进此代码的建议将不胜感激:)。
PHP代码:
<?php
function clean($str)
{
$str = mysql_real_escape_string($str);
$str = htmlspecialchars($str);
$str = strip_tags($str);
return($str);
}
if(isset($_POST['name']) &&
isset($_POST['address']) &&
isset($_POST['hp']) &&
isset($_POST['email']) &&
isset($_POST['rm']) &&
isset($_POST['service']) &&
isset($_POST['name-owner']) &&
isset($_POST['name-rep']) &&
isset($_POST['contract-from']) &&
isset($_POST['contract-to']) &&
isset($_POST['agree']) &&
isset($_POST['submit'])){
$name = clean($_POST['name']);
if($name == NULL || $name == "")
{
die ("Please enter your name");
$errormsg = "<button class=\"\" onClick=\"history.go(-1)\"> Retry</button> ";
}
$address = clean($_POST['address']);
if($address == NULL)
{
die ("Please enter your Business address");
$errormsg;
}
$hp = clean($_POST['hp']);
if($hp == NULL)
{
die ("Please enter your Phone No.");
}
$email = clean($_POST['email']);
if($email == NULL)
{
die ("Please enter your Email address");
$errormsg;
}
$url = clean($_POST['url']);
$rm = clean($_POST['rm']);
if($rm == NULL)
{
die ("Please enter your Amount/Percentage");
$errormsg;
}
$service = clean($_POST['service']);
if($service == NULL)
{
die ("Please enter your Service/Item offer");
$errormsg;
}
$nameowner = clean($_POST['name-owner']);
if($nameowner == NULL)
{
die ("Please enter the Name of Owner/Manager");
$errormsg;
}
$namerep = clean($_POST['name-rep']);
if($namerep == NULL)
{
die ("Please enter the Name of Representative");
$errormsg;
}
$contract_from = clean($_POST['contract-from']);
if($contract_from == NULL)
{
die ("Please enter the Contract date");
$errormsg;
}
$contract_to = clean($_POST['contract-to']);
if($contract_to == NULL)
{
die ("Please enter the Contract date");
$errormsg;
}
$agree = clean($_POST['agree']);
$message = "Business Name: ".$name."\r\n";
$message = "Business Address: " .$address. "\r\n";
$message = "Phone No.: ".$hp."\r\n";
$message = "Email: ".$email."\r\n";
$message = "URL: <a href=\"".$url."\"\r\n ";
$message = "Amount/Percentage offer: ".$rm."\r\n";
$message = "Items/Service offer:".$service."\r\n";
$message = "Name of Owner/Manager".$nameowner."\r\n";
$message = "Name of Representative".$namerep."\r\n";
$message = "This contract is valid for one(1) year from: <b>".$contract_from."</b> to <b>".$contract_to."</b> \r\n";
$message = $agree."\r\n";
$to = 'contact@example.com';
$subject = 'Contact query';
$headers = 'From:' . "$email \r\n" .
'Reply-To:' . "$email \r\n" .
'X-Mailer: PHP/' . phpversion();
$send = mail($to, $subject, $message, $headers);
if ($send == TRUE)
{
echo "<p>Message has been sent</p>";
echo "<p>Thank you</p>";
}
else
{
die ("<p>Message failed to send</p>");
}
}else {
echo "<p>Oops.. There seems to be a technical error<br>We are truly sorry, please check again later</p>";
}
?>
答案 0 :(得分:0)
可能没有设置其中一个 POST 变量,因此它可能会将您带到else部分以显示错误
您必须将require_once "Mail.php";
require_once('Mail/mime.php');
附加到您的代码中,以便该功能适合您
<?php
function clean($str)
{
$str = mysql_real_escape_string($str);
$str = htmlspecialchars($str);
$str = strip_tags($str);
return($str);
}
if(isset($_POST['submit']))
{
$name = clean($_POST['name']);
if($name == NULL || $name == "")
{
die ("Please enter your name");
$errormsg = "<button class=\"\" onClick=\"history.go(-1)\"> Retry</button> ";
}
$address = clean($_POST['address']);
if($address == NULL)
{
die ("Please enter your Business address");
$errormsg;
}
$hp = clean($_POST['hp']);
if($hp == NULL)
{
die ("Please enter your Phone No.");
}
$email = clean($_POST['email']);
if($email == NULL)
{
die ("Please enter your Email address");
$errormsg;
}
$url = clean($_POST['url']);
$rm = clean($_POST['rm']);
if($rm == NULL)
{
die ("Please enter your Amount/Percentage");
$errormsg;
}
$service = clean($_POST['service']);
if($service == NULL)
{
die ("Please enter your Service/Item offer");
$errormsg;
}
$nameowner = clean($_POST['name-owner']);
if($nameowner == NULL)
{
die ("Please enter the Name of Owner/Manager");
$errormsg;
}
$namerep = clean($_POST['name-rep']);
if($namerep == NULL)
{
die ("Please enter the Name of Representative");
$errormsg;
}
$contract_from = clean($_POST['contract-from']);
if($contract_from == NULL)
{
die ("Please enter the Contract date");
$errormsg;
}
$contract_to = clean($_POST['contract-to']);
if($contract_to == NULL)
{
die ("Please enter the Contract date");
$errormsg;
}
$agree = clean($_POST['agree']);
$message = "Business Name: ".$name."\r\n";
$message = "Business Address: " .$address. "\r\n";
$message = "Phone No.: ".$hp."\r\n";
$message = "Email: ".$email."\r\n";
$message = "URL: <a href=\"".$url."\"\r\n ";
$message = "Amount/Percentage offer: ".$rm."\r\n";
$message = "Items/Service offer:".$service."\r\n";
$message = "Name of Owner/Manager".$nameowner."\r\n";
$message = "Name of Representative".$namerep."\r\n";
$message = "This contract is valid for one(1) year from: <b>".$contract_from."</b> to <b>".$contract_to."</b> \r\n";
$message = $agree."\r\n";
$to = 'contact@example.com';
$subject = 'Contact query';
$headers = 'From:' . "$email \r\n" .
'Reply-To:' . "$email \r\n" .
'X-Mailer: PHP/' . phpversion();
$send = mail($to, $subject, $message, $headers);
if ($send == TRUE)
{
echo "<p>Message has been sent</p>";
echo "<p>Thank you</p>";
}
else
{
die ("<p>Message failed to send</p>");
}
}
else
{
echo "<p>Oops.. There seems to be a technical error<br>We are truly sorry, please check again later</p>";
}
?>