Jump to content

Recommended Posts

Hey guys, I encoutered something strange in php, or maybe it suppose to.

so i created a mail function then call it using if else statement, base on that, i send out email  to one person if conditon meets require criteria then email anoter person in else... but it execute the if condition (that's fine) and it also execute the else condition too, both emails got send. I thought only one condition got executed.

heres the mail function

function email($to,$message)//create email function
{
	$subject = "Please Ignore";
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

	$headers .= 'From: <[email protected]>' . "\r\n";
	mail($to,$subject,"<strong>".'Expiration Status'."</strong>"."<br />"."<br />" .$message,$headers);
}

here's the if else sending mail condition

$file = file_get_contents ('content.html', true);//get content from file for reading
if (preg_match('/WSNet/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'WSNet' ."<br />"."<br />". $file);
}
else{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'No expire apps between now and the next 60 days' ."<br />"."<br />". $file);
	}

so the if condition met and sending email to me, shouldn't the else condition be ignored? but it send email to me too...

thanks for the help

thanks for reply Sensei.

Yes I only run it once,

and i tested the preg_match

<?php 
$file = file_get_contents ('content.html', true);
if (preg_match('/Google Search Appliance/', $file))//search the match keyword under the app_owner 
{
	echo 'Google Search Appliance found';
}
else 
{
	echo 'Google Search Appliance not found';
}	
?>

Google Search Appliance is in the file so it echo found. and else never executed. and when it's not found the else exectued. so that seems to work fine. don't where the bug is  :(

here's the full code,

<html>
<head>
<title>Email Application</title>
</head>
<body>

<?php		
function email($to,$message)//create email function
{
	$subject = "Please Ignore";
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

	$headers .= 'From: <[email protected]>' . "\r\n";
	mail($to,$subject,"<strong>".'Expiration Status'."</strong>"."<br />"."<br />" .$message,$headers);
}	
$file = file_get_contents ('content.html', true);//get content from file for reading
if (preg_match('/ADAM\/ MIIS\/ LDAP/',$file))//search the match keyword under the app_owner 'ADAM / MIIS / LDAP'
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'ADAM / MIIS / LDAP' ."<br />"."<br />". $file);//mail the owners
}
if (preg_match('/AMAG SMS/', $file))
{
	email('[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'AMAG SMS' ."<br />"."<br />". $file);
}
if (preg_match('/Aspect eWFM/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Aspect eWFM' ."<br />"."<br />". $file);
}
if (preg_match('/Aspect RTA/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Aspect RTA' ."<br />"."<br />". $file);
}
if (preg_match('/AutoSys \/ iXp Agent/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'AutoSys / iXp Agent' ."<br />"."<br />". $file);
}
if (preg_match('/BES Standard, BlackBerry/', $file))
{
	email('#[email protected]',"<strong>".'Expire App: '."</strong>".'BES Standard, BlackBerry' ."<br />"."<br />". $file);
}
if (preg_match('/Clarify/', $file))
{
	email('[email protected], [email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'Clarify' ."<br />"."<br />". $file);
}
if (preg_match('/Clients and Profits/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Clients and Profits' ."<br />"."<br />". $file);
}
if (preg_match('/Connect: Direct/', $file))
{
	email('[email protected], [email protected], [email protected], 
			[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'Connect: Direct' ."<br />"."<br />". $file);
}
if (preg_match('/ConnectShip/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'ConnectShip' ."<br />"."<br />". $file);
}
if (preg_match('/CorpTax/', $file))
{
	email('#OWNED@dishnetwork,com',"<strong>".'Expire App: '."</strong>".'CorpTax' ."<br />"."<br />". $file);
}
if (preg_match('#CSG / ACSR#', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'CSG' ."<br />"."<br />". $file);
}
if (preg_match('/DeskAlerts/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'DeskAlerts' ."<br />"."<br />". $file);
}
if (preg_match('/ELM \/ iLearning/', $file))
{
	email('[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'ELM / iLearning' ."<br />"."<br />". $file);
}
if (preg_match('/F-Secure Anti-Virus/', $file))
{
	email('[email protected], [email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'F-Secure Anti-Virus' ."<br />"."<br />". $file);
}
if (preg_match('/F5 \/ Big-IP/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'F5 / Big-IP' ."<br />"."<br />". $file);
}
if (preg_match('/FileNet/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'FileNet' ."<br />"."<br />". $file);
}
if (preg_match('/GEAC MPC/', $file)) 
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'GEAC MPC' ."<br />"."<br />". $file);
}
if (preg_match('/Gemini Scanner/', $file))
{
	email('[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'Gemini Scanner' ."<br />"."<br />". $file);
}
if (preg_match('/Google Search Appliance/', $file))//search the match keyword under the app_owner 
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Google Search Appliance' ."<br />"."<br />". $file);
}
if (preg_match('/Hyperion \/ OBIEE/', $file))
{
	email('[email protected], [email protected], [email protected], [email protected], 
			[email protected], [email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'Hyperion / OBIEE' ."<br />"."<br />". $file);
}
if (preg_match('/Instant Service/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Instant Service' ."<br />"."<br />". $file);
}
if (preg_match('/Kronos Workforce Central/', $file))
{
	email('[email protected], [email protected], [email protected], 
			[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'Kronos Workforce' ."<br />"."<br />". $file);
}
if (preg_match('/Liquid Engines/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Liquid Engines' ."<br />"."<br />". $file);
}
if (preg_match('/Merced \/ DishMetrics/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Merced / DishNetrics' ."<br />"."<br />". $file);
}
if (preg_match('/PGP/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'PGP' ."<br />"."<br />". $file);
}
if (preg_match('/PL\/SQL Developer/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'PL / SQL Developer' ."<br />"."<br />". $file);
}
if (preg_match('/PTMS/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'PTMS' ."<br />"."<br />". $file);
}
if (preg_match('/SecureAuth/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'SecureAuth' ."<br />"."<br />". $file);
}
if (preg_match('/Siebel/', $file))
{
	email('[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'Siebel' ."<br />"."<br />". $file);
}
if (preg_match('/Stoneriver Tracker/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'Stoneriver Tracker' ."<br />"."<br />". $file);
}
if (preg_match('/TeamMate/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'teamMate' ."<br />"."<br />". $file);
}
if (preg_match('/TeamTrack/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'TeamTrack' ."<br />"."<br />". $file);
}
if (preg_match('/WCCMS/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'WCCMS' ."<br />"."<br />". $file);
}
if (preg_match('/WebMethods/', $file))
{
	email('[email protected], [email protected], [email protected], 
			[email protected], [email protected]',"<strong>".'Expire App: '."</strong>".'WebMethods' ."<br />"."<br />". $file);
}
if (preg_match('/WSNet/', $file))
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'WSNet' ."<br />"."<br />". $file);
}
else
{
	email('[email protected]',"<strong>".'Expire App: '."</strong>".'No expire apps between now and the next 60 days' ."<br />"."<br />". 'relax');
}
?>
</body>
</html>

the content of the $file is in the picture,

 

[attachment deleted by admin]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.