Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Different behavior for different users

I have this javascript code in one program:

if (ac == "r") {
			document.st.rfq.disabled = true;
			document.st.rfq.value = "Proessing Request...";
			setTimeout(restore_rfq, 5000);
			window.open("rfq.php", "rfq", "width=650, height=500, left=800, top=300, scrollbars=yes, menubar=yes, resizable=yes");
			return false;
		}	

Open in new window


Works fine, opens a new browser window, which has this code:
<!DOCTYPE html>
<?php
include "db_connect_nb.php";
$country = "";
	if (isset($_GET['country'])){ 
		$country = $_GET['country'];
	}	
	$hass = false;
	if($country == "United States" || $country == "Mexico" || $country == "Canada") {
		$hass = true;
	}	
	if ($hass) {
		$qry = "SELECT * from states where country_code = '" . $country . "' order by name";
		$res = mysqli_query($link, $qry);
		$ns = mysqli_num_rows($res);
	}	
	$qryc = "SELECT * from countries";
	$resc = mysqli_query($link, $qryc);
	$nc = mysqli_num_rows($resc);
?>
<html>
<head>
<meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="W3.css">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<title>Request for Quote</title>
<script type="text/javascript">
function chk_vals() {
		if (document.st.fname.value == "") {
			alert("All fields required.");
			return false;
		}	
		if (document.st.lname.value == "") {
			alert("All fields required.");
			return false;
		}
		if (document.st.country.value == "") {
			alert("All fields required.");
			return false;
		}			
		if (document.st.state.value == "") {
			alert("All fields required.");
			return false;
		}	
		if (document.st.phone.value == "") {
			alert("All fields required.");
			return false;
		}	
		if (document.st.city.value == "") {
			alert("All fields required.");
			return false;
		}	
		if (document.st.company.value == "") {
			alert("All fields required.");
			return false;
		}
		if (document.st.email.value == "") {
			alert("All fields required.");
			return false;
		}			
		return true;
	}
	function get_states() {
	str = "&fn=" + document.st.fname.value + "&ln=" + document.st.lname.value + "&tt=" + document.st.title.value + "&co=" + document.st.company.value + "&ph=" + document.st.phone.value + "&em=" + document.st.email.value + "&city=" + document.st.city.value;
	document.st.action = "rfq.php?country=" + document.st.country.value + str;
	document.st.submit();
}	
</script>	
</head>
<body>
<form method="post" name="st" action="rfq_email.php" onSubmit="return chk_vals();">
<div class="container-fluid" >
<div class="row">
	<div class="col-sm-10 col-xs-10 text-center" style="font-size:20px; padding-top:20px;">To request a quote, enter your information.</div>
</div>	
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">First Name:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><input type="text" name="fname" size="15" value="<? print $_GET['fn']; ?>"></div>
</div>	
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">Last Name:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><input type="text" name="lname" size="15" value="<? print $_GET['ln']; ?>"></div>
</div>
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">Country:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><select name="country" style="font-size:18px" onChange="get_states();">
		<option value="">--- Select Country ---</option>
		<? for ($i = 0; $i < $nc; $i++) {
			$c = mysqli_fetch_array($resc,MYSQLI_ASSOC);
			$sel = "";
			if ($country != "") {
				if ($country == $c['country'] ) {
					$sel = "selected";
				} 
			}	?>
			<option value="<? print $c['country']; ?>" <? print $sel; ?>><? print $c['country']; ?></option>
		<? } ?>	
	</select></div>
</div>
<? if ($country != "" && $country != "Other") { ?>
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;"><? if ($country == "Canada") { ?>Province:<? } else { ?>State:<? } ?></div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><select name="state" style="font-size:18px">
		<option value=""><? if ($country == "Canada") { ?>--- Province ---<? } else { ?>--- State ---<? } ?></option>
		<? for ($i = 0; $i < $ns; $i++) {
			$s = mysqli_fetch_array($res,MYSQLI_ASSOC); ?>
			<option value="<? print $s['state']; ?>"><? print $s['name']; ?></option>
		<? } ?>
		</select></div>
</div>
<? } ?>
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">City:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><input type="text" name="city" size="15" value="<? print $_GET['city']; ?>"></div>
</div>
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">Phone Number:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><input type="text" name="phone" size="15" value="<? print $_GET['ph']; ?>"></div>
</div>
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">Company:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><input type="text" name="company" size="15" value="<? print $_GET['co']; ?>"></div>
</div>	
<div class="row">
	<div class="col-sm-5 col-xs-5 text-right" style="font-size:18px;padding-top:20px;">Email Address:</div>
	<div class="col-sm-5 col-xs-5" style="font-size:18px;padding-top:20px;"><input type="text" name="email" size="15" value="<? print $_GET['em']; ?>"></div>
</div>
<div class="row">
	<div class="col-sm-10 col-xs-10 text-right" style="font-size:18px;padding-top:20px;"><input type="submit" value="Submit"></div>
</div>
</div>	
</form>
</body>
</html>

Open in new window


When the submit button is clicked (by me), the window is filled by this code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
	// rfq_email.php
	session_start(); 
	require_once('class.phpmailer.php');
	include "db_connect_nb.php";
	$usertyp = "noprice";
	if ($_SESSION['ruid'] == "" && $_SESSION['guest'] != "y") {
		exit;
	}	
	if ($_SESSION['ruid'] != "") {
		$qry = "SELECT * from registered_users where ix = " . $_SESSION['ruid'];
		$res = mysqli_query($link, $qry);
		$ru = mysqli_fetch_array($res,MYSQLI_ASSOC);
		if ($ru['see_pricing'] != "Y" && $ru['net_pricing'] !="Y") {
			$usertyp = "reg";
		}
	}		
	$mail             = new PHPMailer(); // defaults to using php "mail()"
//echo "got into rfq_email<br>";
$mail->isSMTP(); // telling the class to use SMTP transport
 
$body             = "";
 
$mail->SetFrom('noreply@lakos.com');
  
$address = "Prashant.Joshi@lakos.com";
$mail->AddAddress($address);
$address = "richardkorts@gmail.com";
$mail->AddAddress($address);
$address = "Zachary.Ormonde@lakos.com";
$mail->AddAddress($address);
$mail->AddAddress("lakos_receptionist@lakos.com");
$mail->AddAddress("lit@lakos.com");
$mail->Subject    = "Request For Quote";
$str = "A guest user has requested a quote for product ";
if ($usertyp == "reg") {
	$str = "A registered user with no pricing has requested a quote for product ";
}	
$body = $body . $str . $_SESSION['model']. "<br><br>";
$body = $body . "Name: " . $_POST['fname'] . " " . $_POST['lname'] . "<br><br>";
$body = $body . "Company: " . $_POST['company'] . "<br><br>";
$body = $body . "Email: " . $_POST['email'] . "<br><br>";
$body = $body . "Phone Number: " . $_POST['phone'] . "<br><br>";
$body = $body . "Country: " . $_POST['country'] . "<br><br>";
$body = $body . "State: " . $_POST['state'] . "<br><br>";
$body = $body . "City: " . $_POST['city'] . "<br><br>";
$body = $body . "Model: " . $_SESSION['model'] . "<br>";
$body = $body . "Purge: " . $_SESSION['purge'] . "<br>";
$body = $body . "Voltage: " . $_SESSION['voltage'] . "<br>";
$body = $body . "Configuration request attached.";
$mail->MsgHTML($body);
// attach summary
//echo "session['vid'] = " . $_SESSION['vid'] . "<br>";
$attach = "summaries/" . $_SESSION['vid'] . "summary_np.pdf";
$mail->AddAttachment($attach); 
if(!$mail->Send()) {
	echo "Mailer Error: " . $mail->ErrorInfo;
}
// 2nd email to the requestor
	$mail1             = new PHPMailer(); // defaults to using php "mail()"

$mail1->isSMTP(); // telling the class to use SMTP transport
 
$body1             = "";
 
$mail1->SetFrom('noreply@lakos.com');
if ($usertyp == "reg") {
	$body1 = "Dear " . $ru['firstname'] . ",<br><br>";
} else {
	$body1 = "Dear Guest,<br><br>";
}
$body1 = $body1 . "Your quote request has been received. A distributor located in your area will contact you with pricing.<br><br>";
$body1 = $body1 . "If you do not receive a response from our distributor, please contact us at lit@lakos.com or 1 (559) 255-1601. Thank you for using the Lakos HT Product Configurator.<br><br>";
$body1 = $body1 . "If you have received this message in error, please forward it to lit@lakos.com.<br><br>";
$mail1->AddAddress($_POST['email']);
$mail1->MsgHTML($body1);
if(!$mail1->Send()) {
	echo "Mailer Error: " . $mail1->ErrorInfo;
}	
?>
<!DOCTYPE html>

<html>
<head>
<title></title>
<meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="W3.css">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript">
function timed_close() {
	setTimeout(function(){ self.close(); }, 3000);
}
</script>
<!-- Global site tag (gtag.js) - Google
Analytics -->

<script async
src="https://www.googletagmanager.com
/gtag/js?id=UA-96994211-3"></script>

<script>
window.dataLayer = window.dataLayer
|| [];
function
gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-96994211-3');
</script>
</head>
<body onLoad="timed_close();">
<div class="container-fluid" >
<div class="row">
	<div class="col-sm-10 col-xs-10 text-center" style="font-size:22px; padding-top:60px;">Message sent to Lakos requesting Quote.</div>
</div>	

</body>
</html>

Open in new window


The window then closes in 3 seconds, as directed.

For another user, clicking Submit (in the second php program) does not replace the contents of the window, thus does not load the third php program, thus no emais sent.

I and the other user are both using Windows 10 (I presume force updated to the latest version), we are both using Chrome, my version is Version 77.0.3865.120 (Official Build) (64-bit), his version is Version 77.0.3865.90 (Official Build) (64-bit), a very slight change.

Where else can I look to explain the difference in functionality?

Thanks
Avatar of ste5an
ste5an
Flag of Germany image

Just a comment:

I would decouple it. Just store the request for sending the e-mail in your database. Let an external service poll this "job" table in an appropriate interval and send the mails.

E-mail is an asynchronous communication channel, there is no need to do sent it immediately in many processes.

Also your current code needs to handles static text, which should be controlled by e-mail templates of some kind.
Avatar of Richard Korts

ASKER

ste5an,

Thanks for those things.

The issue seems to be it works as is for me and at least some others, but not for at least one other.

And has for several years.

Thanks
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.