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

它不会向PHP发送消息(电子邮件),php,email,Php,Email,我不知道为什么它不会发送,只是echo的这个消息。。似乎有一个技术错误,我们非常抱歉,请稍后再检查 我不知道有什么问题也许我忽略了, 你能告诉我我做错了吗。 如果你需要html代码,请告诉我 对于如何改进本规范的建议,我们将不胜感激: PHP代码: <?php function clean($str) { $str = mysql_real_escape_string($str); $str = htmlspecialchars($str); $str = strip_tags($str)

我不知道为什么它不会发送,只是echo的这个消息。。似乎有一个技术错误,我们非常抱歉,请稍后再检查

我不知道有什么问题也许我忽略了, 你能告诉我我做错了吗。 如果你需要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变量未设置,因此它可能会将您抛出到else部分以显示错误 必须附加require_once Mail.php;需要_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>";
    }
?>

你有邮件服务器设置吗?事实上,看起来最后一个是来自你在顶部的大量ISSET。显然有些东西没有设置是的,我有,我的联系我们表单使用了相同的代码,它可能只是通过复制和粘贴工作,但是如果你有适当的缩进,你就能够看到你一直收到的消息,错误是你的一系列ISSET的结果,因此,有些东西没有设置。你也应该开始数数。。。由于使用mysql函数,代码停止工作的天数。在它成为一个大问题之前,立即修复它!:我尝试删除该函数并删除除submit之外的所有isset,但仍然是一样的