Lucas Meine
Lucas Meine

Reputation: 1619

strange behavior on contact form

I am having a strange problem with this form. I have made it yesterday night and it was working fine, sending all the emails as it should. However, I've run it today and it won't simply work at all. I am always getting the error message. Any clues? Thank you.

 <?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>";
}
?>

Upvotes: 0

Views: 58

Answers (2)

Kevin
Kevin

Reputation: 6701

You should enclose strings within quotes. Moreover, == (comparing objects of different types) && === (comparing objects of same types) are used for comparing and = is used for assigning. So, change the code as follows (inside the if statements) :

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

Upvotes: 2

Artur
Artur

Reputation: 7257

Instead of = use == for comparison

for example - instead of:

if( $depart = administrativo)

use

if( $depart == "administrativo" )

Upvotes: 3

Related Questions