This question already has an answer here:
i dont know why it wont send
it just echo's this msg
Oops.. There seems to be a technical error
We are truly sorry, please check again later
i dont know whats the problem maybe i'm overlooking,
can u pls tell me i have i gone wrong.
if you need the html code let me know
suggestions on how to improve this code would be gratefully appreciated :)
PHP CODE:
<?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."
";
$message = "Business Address: " .$address. "
";
$message = "Phone No.: ".$hp."
";
$message = "Email: ".$email."
";
$message = "URL: <a href=\"".$url."\"
";
$message = "Amount/Percentage offer: ".$rm."
";
$message = "Items/Service offer:".$service."
";
$message = "Name of Owner/Manager".$nameowner."
";
$message = "Name of Representative".$namerep."
";
$message = "This contract is valid for one(1) year from: <b>".$contract_from."</b> to <b>".$contract_to."</b>
";
$message = $agree."
";
$to = 'contact@example.com';
$subject = 'Contact query';
$headers = 'From:' . "$email
" .
'Reply-To:' . "$email
" .
'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>";
}
?>
</div>
Probably one of the POST Variable is not set and thus it might throw you to the else part to show the error You must attach the require_once "Mail.php";
require_once('Mail/mime.php');
into your code so that the function works for you
<?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."
";
$message = "Business Address: " .$address. "
";
$message = "Phone No.: ".$hp."
";
$message = "Email: ".$email."
";
$message = "URL: <a href=\"".$url."\"
";
$message = "Amount/Percentage offer: ".$rm."
";
$message = "Items/Service offer:".$service."
";
$message = "Name of Owner/Manager".$nameowner."
";
$message = "Name of Representative".$namerep."
";
$message = "This contract is valid for one(1) year from: <b>".$contract_from."</b> to <b>".$contract_to."</b>
";
$message = $agree."
";
$to = 'contact@example.com';
$subject = 'Contact query';
$headers = 'From:' . "$email
" .
'Reply-To:' . "$email
" .
'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>";
}
?>