• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Why does this work on one server, but not on another?

The following script is an email thing that sends the user their password info. It works on my server on brucegust.com, but it doesn't do anything on rodgerstkd.com. No errors, mind you, just no email.

What do I need to change, or what could possibly be going on with the rodgerstkd.com server that is distinctive when compared to brucegust.com?

Here's my code:

<?php require_once('header.php'); ?>
<?php
$email = trim($_POST['email']);

$query = "select * from students where email='$email'";
$result = mysqli_query($cxn, $query);
	if(!$result) {
	$error = mysqli_errno($cxn).': '.mysqli_error($cxn);
	die($error);
	} 			
$rowCount = mysqli_num_rows($result);
	if(!$rowCount>0){
	header("Location:student_email_not_found.php");
	exit();
	}
	else
	{
		if($rowCount>1)
		{
		$to = $email;
		$subject = "Rodgers TKD Student Password Info";

		$message = "
		<html>
		<head>
		<title>Rodgers TKD Student Password Info</title>
		</head>
		<body><br>
		Here the userids and passwords associated with the email address you just entered...<br><br>
		<table width=\"600\" border=\"1\">
		<tr>
			<td style=\"background-color:#cccccc;\">name:</td>
			<td style=\"background-color:#cccccc;\">userid:</td>
			<td style=\"background-color:#cccccc;\">password</td>
		</tr>";
		while($queryrow=mysqli_fetch_assoc($result))
		{
		extract($queryrow); 
		$message .="
		<tr>
			<td>";
			$message .= stripslashes($queryrow['first_name']).' '.stripslashes($queryrow['last_name']);
			$message .="</td><td>";
			$message .= $queryrow['userid'];
			$message .="</td><td>";
			$message .= $queryrow['password'];
			$message .="</td></tr>";
			}
			$message .="</table></body></html>";
	

		// Always set content-type when sending HTML email
		$headers = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

		// More headers
		$headers .= 'From: <Suzi.rodgers@rodgerstkd.com>' . "\r\n";

		mail($to,$subject,$message,$headers);

		 }
		 else
		{
		$queryrow=mysqli_fetch_assoc($result);
		extract($queryrow);
		$the_password = stripslashes($queryrow['password']); 
		$the_first_name = stripslashes($queryrow['first_name']);
		$the_userid = stripslashes($queryrow['userid']);
		$to = $email;
		$subject = "Your Tae Kwon Do Password";
		$message = "Hello, $the_first_name!\n\nYour TKD password is $the_password and your userid is $the_userid.\n\nThanks!";
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers = "From: Suzi.rodgers@rodgerstkd.com\r\n" ."X-Mailer: php";

			 if (!mail($to, $subject, $message, $headers)) {
			   echo("<p>Message delivery failed...</p>");
			  }
			}
		}
?>
<div id="satellite_text_box">
<IMG SRC="images/title_student_page.jpg">
<P>
<div id="main_content">
	<table width=100%>
	<tr>
	<td class="title_bar">&nbsp;Password Sent
	</td>
	</tr>
	<tr>
	<td><BR>
	Your password has been sent to <?php echo $email; ?>.
	<P>
	Thanks!
	</td>
	</tr>
	</table>
</div></div>
<?php require_once('footer_satellite.php'); ?>

Open in new window


What do you think?
0
brucegust
Asked:
brucegust
3 Solutions
 
GaryCommented:
Is error reporting turned on?
Do you have a mail server on the other server?
0
 
nemws1Commented:
Agree with Gary - mail probably isn't configured on 'rodgerstkd.com'.

Also, make *SURE* you sanitize your HTML input!  The way you have this written, somebody can easily pass this in the email field and start using your form to send SPAM:

$email = 'blah@whatever.com\nCC: spam1@spam.com,spam2@spam.com,spam3@spam.com'

Open in new window

0
 
Randy PooleCommented:
In your php.ini make sure your smtp setting is to the mailserver ip or hostname and the smtp_port is configured to what you are expecting.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
brucegustAuthor Commented:
nemws1 - I took your advice and sanitized the email address so now the $email variable is $email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL); .

The server administrator sent this back to me. I'm not familiar with the syntax, so I don't even know where to start or what to tell him. Can any of y'all tell me what's going on and what I need to do to ensure that my email gets delivered?

This is what he sent me when he stated that he was able to send an email manually without any issues:

[root@web log]# telnet 68.178.213.203 25
Trying 68.178.213.203...
Connected to 68.178.213.203.
Escape character is '^]'.
220 p3plibsmtp03-06.prod.phx3.secureserver.net bizsmtp ESMTP server ready
ehlo rodgerstkd.com
250-p3plibsmtp03-06.prod.phx3.secureserver.net hello [204.29.15.166], pleased to meet you
250-HELP
250-SIZE 104857600
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 OK
mail from: eric@telic.us
250 2.1.0 <eric@telic.us> sender ok
rcpt to: bruce@brucegust.com
250 2.1.5 <bruce@brucegust.com> recipient ok
data
354 enter mail, end with "." on a line by itself
test
.
250 2.0.0 f6cW1o02J3ayBFQ01 - f6cW1o02J3ayBFQ016cnaN mail accepted for delivery
quit
221 2.0.0 p3plibsmtp03-06.prod.phx3.secureserver.net bizsmtp closing connection
Connection closed by foreign host.

Open in new window


This is the first email he sent. Again, I'm not up to speed on what this means or how it could translate to an action item for me where my code is concerned:

Different box.  Mail.rodgerstkd.com for smtp.  I’ll have to put an allow in for unauthenticated smtp but shouldn’t be an issue….   Wait a sec.  There is outgoing mail service on the localhost of that box.  You should be able to use 127.0.0.1 or localhost as the server.  Where is the code that is trying to send?

Server doesn’t look wrong here?  It got the email from the webserver without issues:

Aug 15 08:45:21 web sendmail[29932]: s7FDjLuA029932: from=apache, size=238, class=0, nrcpts=1, msgid=<201408151345.s7FDjLuA029932@web.iristransport.net>, relay=apache@localhost
Aug 15 08:45:31 web sendmail[29933]: s7FDjLGn029933: from=<apache@web.iristransport.net>, size=475, class=0, nrcpts=1, msgid=<201408151345.s7FDjLuA029932@web.iristransport.net>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Aug 15 08:45:31 web sendmail[29932]: s7FDjLuA029932: to=bruce@brucegust.com, ctladdr=apache (48/48), delay=00:00:10, xdelay=00:00:10, mailer=relay, pri=30238, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (s7FDjLGn029933 Message accepted for delivery)

Found the outbound attempt.  Being rejected at that end but no reason other than “Service unavailable”

Aug 14 14:12:11 web sendmail[28795]: s7EJC0Fo028793: to=<bruce@brucegust.com>, ctladdr=<apache@web.iristransport.net> (48/48), delay=00:00:06, xdelay=00:00:06, mailer=esmtp, pri=120443, relay=smtp.secureserver.net. [68.178.213.203], dsn=5.0.0, stat=Service unavailable
Aug 15 08:08:14 web sendmail[29907]: s7FD88Yl029907: to=bruce@brucegust.com, ctladdr=apache (48/48), delay=00:00:06, xdelay=00:00:05, mailer=relay, pri=30230, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (s7FD89nq029908 Message accepted for delivery)
Aug 15 08:08:21 web sendmail[29910]: s7FD89nq029908: to=<bruce@brucegust.com>, ctladdr=<apache@web.iristransport.net> (48/48), delay=00:00:07, xdelay=00:00:07, mailer=esmtp, pri=120467, relay=smtp.secureserver.net. [72.167.238.29], dsn=5.0.0, stat=Service unavailable
Aug 15 08:45:31 web sendmail[29932]: s7FDjLuA029932: to=bruce@brucegust.com, ctladdr=apache (48/48), delay=00:00:10, xdelay=00:00:10, mailer=relay, pri=30238, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (s7FDjLGn029933 Message accepted for delivery)
Aug 15 08:45:33 web sendmail[29935]: s7FDjLGn029933: to=<bruce@brucegust.com>, ctladdr=<apache@web.iristransport.net> (48/48), delay=00:00:07, xdelay=00:00:02, mailer=esmtp, pri=120475, relay=smtp.secureserver.net. [68.178.213.203], dsn=5.0.0, stat=Service unavailable

And 2 different boxes on that side.

Open in new window


What's my dilemma and what can I do to fix it?
0
 
GaryCommented:
You're on GoDaddy - groan.

Are you sure you have your SMTP/Email setup corretly?
http://support.godaddy.com/help/article/3552/managing-your-email-account-smtp-relays
0
 
brucegustAuthor Commented:
Actually, Gary, I don't think I'm on godaddy. The guy I'm working with has given me the impression he's got me on a box somewhere with his company. I say that because in the past he's stressed a secure connection and he's gone as far as restricted me from uploading anything directly.

So, that said, I don't know what his emails mean or what's indicated by saying that he sent an email manually without an incident.

What do his emails mean as far as what needs to change with my code? Or does anything need to change with my code?
0
 
GaryCommented:
Bruce can you bump this tomorrow, had problems with EE the past few hours and off to the bar now as you do on a Friday!
0
 
brucegustAuthor Commented:
Morning, sir!

I'm reviewing the way things have been approached up to this point and the logic appears to be:

- email isn't being sent from his server when the password_send.php page is used (rodgerstkd.com/password_send.php)
- password_send.php fires just fine on my server (brucegust.com/rodgers/password_send.php)
- there are no errors on the password_send.php when we run it from rodgerstkd.com
- he attempts to trouble shoot my using a command line approach that sends an email from his server to bruce@brucegust.com
- the email he sends doesn't arrive at bruce@brucegust.com which suggests that something is wrong on godaddy
- I suggest that he try to run a scenario from brucegust.com/rodgers/password_send.ph using his login information. He does and the email arrives fine at eric@telic.us

Having just got off the phone with godaddy and relayed the "Service unavailable" error to them when a person attempted to email me at bruce@brucegust.com, they double checked the health of my account and were able to report that everything looks good on their end, which means that "Service unavailable" isn't indicative of a bad email or a flawed email server, rather it means that the initiating server wasn't able to make a connection.

So we're back to square one, but perhaps with a more clear perspective on the fact that if the code runs fine on a different server and there are no errors on the page regardless of the server the page is running on, then by process of elimination the problem is with the initiating server not being able to make a connection to any kind of email service, regardless of the email itself.

Does that sound logical?
0
 
GaryCommented:
brucegust.com is on GoDaddy
You are sending an email from rodgerstkd.com to brucegust.com - correct?

But GoDaddy is refusing/not connecting.
0
 
brucegustAuthor Commented:
Yes.

The code seems fine, but for some reason when his server attempts to connect and send an email, something falls short and while there's no error, there's no email.

He tried to test the integrity of the connection by sending an email from a command line prompt and tried to send it to bruce@brucegust.com and his server couldn't make a connection to godaddy.

Called godaddy this am, there's nothing wrong / nothing to see

So the bottom line is that you've got a page that works, as far as there being no errors and fires fine on a different server, but on his server it doesn't work and no one knows why.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now