它不会发送消息(电子邮件)PHP


It wont send the message (EMAIL)PHP

我不知道它为什么不发送
它只是回显这条消息

哦。。似乎有一个技术错误
我们真的很抱歉,请稍后再次检查

我不知道问题出在哪里,也许我忽略了,
你能告诉我我错了吗
如果您需要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>";
}
?>

可能其中一个POST变量未设置,因此它可能会将您转到其他部分以显示错误您必须将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>";
    }
?>