Link to home
Start Free TrialLog in
Avatar of King_Diamond
King_Diamond

asked on

Php - If Statement not working

I'm using the following script to notify mail delivery.

if (($to_name !="") || ($to_email !="")){
if (@mail($to_name, $subject, $message, $headers)) {
  echo("<p>Mail Delivered</p>");
} else {
  echo("<p>Mail Undelivered</p>");
}
}

The problem is that if $to_name or $to_email is empty, this loop is not skipped. I tried empty function but with same result.

Any help is much appreciated.
Avatar of AlexanderR
AlexanderR
Flag of Canada image

It works fine for me:
if (($to_name !="") || ($to_email !="")){

  echo("<p>Mail Delivered</p>");
} else  {
  echo("<p>Mail Undelivered</p>");

}
returns "Mail undelivered"

and

$to_name='name';

if (($to_name !="") || ($to_email !="")){

  echo("<p>Mail Delivered</p>");
} else  {
  echo("<p>Mail Undelivered</p>");

}
it returns "mail delivered".


May be there is some misunderstanding.
At the moment the email will be sent as long as AT LEAST ONE of those variables have a value.  If you want BOTH to have a value prior to sending then you need to have
if (($to_name !="") && ($to_email !="")){

If you are aware of that, then perhaps there is something in your script that gives it a value.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of King_Diamond
King_Diamond

ASKER

You're right angelllll, my "logic" was wrong.

Thanks mate.