联系表格上的奇怪行为

时间:2013-11-30 17:33:35

标签: php

我对这张表格有一个奇怪的问题。我昨天晚上做了它,它工作正常,发送所有的电子邮件应该。但是,我今天运行它并不会简单地工作。我总是收到错误消息。有线索吗?谢谢。

 <?php
$name     =   $_POST['name']; 
$email    =   $_POST['email']; 
$subject  =   $_POST['subject']; 
$message  =   $_POST['message']; 
$depart = $_POST['departamento']; 

$headers  = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";



   $corpo = "Nova Mensagem\n";
   $corpo .= "De: " . $name . "\n"; 
   $corpo .= "Email: " . $email . "\n";
   $corpo.=" Para o departamento " . $depart. "\n";
   $corpo .= "Mensagem: " . $message . "\n";
    if ($depart = administrativo)
     {
      $email_to = ''; 
       }
       elseif ($depart = financeiro)
       {
       $email_to = ''; 
        }
   elseif ($depart = Suporte)
         {
    $email_to = ''; 
      }
     else
      {
     $email_to = ''; 
    }


$status = mail($email_to, $subject, $corpo, $headers); 

if($status) {
    echo "<script> window.location.href = ''; </script>";
}
else {
    echo "<script> window.location.href = ''; </script>";
}
?>

2 个答案:

答案 0 :(得分:3)

而不是 = 使用 == 进行比较

例如

- 而不是:

if( $depart = administrativo)

使用

if( $depart == "administrativo" )

答案 1 :(得分:2)

您应该将字符串括在quotes中。此外,==(比较不同类型的对象)&amp;&amp; ===(比较相同类型的对象)用于比较,=用于分配。因此,请按如下所示更改代码(在if语句中):

if ($depart == 'administrativo')
{
    $email_to = ''; 
}
elseif ($depart == 'financeiro')
{
    $email_to = ''; 
}
elseif ($depart == 'Suporte')
{
    $email_to = ''; 
}
else
{
    $email_to = ''; 
}