-3

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."\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>";

}
?>
Jonathan
  • 113
  • 12
  • Do you have a mail server setup? Actually it looks like that last else is coming from your slew of issets at the top. Apparently something is not set – ElefantPhace Sep 08 '14 at 04:33
  • yes i do, i kinda use the same code for my contact us form, and it works – Jonathan Sep 08 '14 at 04:35
  • May just be from copying and pasting, but if you had proper indentation you'd be able to see where and why you keep getting that message – ElefantPhace Sep 08 '14 at 04:38
  • That error is the result of your series of `isset`s, therefore, something is not set. You should also start counting... how many days until your code stops working because you're using `mysql_` functions. Fix it now before it becomes a huge problem! :) –  Sep 08 '14 at 04:43
  • i tried removing the function and remove all the isset except for submit, but still the same – Jonathan Sep 08 '14 at 04:53
  • Btw your clean function doesnt protect you from getting abused (e.g. by mail header splitting) – MrTux Sep 08 '14 at 04:54
  • oh yeah and the validation is not validating as well – Jonathan Sep 08 '14 at 04:59

1 Answers1

0

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."\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>";
    }
?>
Mohit S
  • 13,723
  • 6
  • 34
  • 69