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'); ?>
$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);
$rowCount = mysqli_num_rows($result);
		$to = $email;
		$subject = "Rodgers TKD Student Password Info";

		$message = "
		<title>Rodgers TKD Student Password Info</title>
		Here the userids and passwords associated with the email address you just entered...<br><br>
		<table width=\"600\" border=\"1\">
			<td style=\"background-color:#cccccc;\">name:</td>
			<td style=\"background-color:#cccccc;\">userid:</td>
			<td style=\"background-color:#cccccc;\">password</td>
		$message .="
			$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";


		$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">
<div id="main_content">
	<table width=100%>
	<td class="title_bar">&nbsp;Password Sent
	Your password has been sent to <?php echo $email; ?>.
<?php require_once('footer_satellite.php'); ?>

Open in new window

What do you think?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is error reporting turned on?
Do you have a mail server on the other server?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nemws1Database AdministratorCommented:
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

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.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

brucegustPHP DeveloperAuthor 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 25
Connected to
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 [], pleased to meet you
250-SIZE 104857600
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
354 enter mail, end with "." on a line by itself
250 2.0.0 f6cW1o02J3ayBFQ01 - f6cW1o02J3ayBFQ016cnaN mail accepted for delivery
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 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 []
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=[] [], 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. [], 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=[] [], 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. [], 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=[] [], 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. [], 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?
You're on GoDaddy - groan.

Are you sure you have your SMTP/Email setup corretly?
brucegustPHP DeveloperAuthor 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?
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!
brucegustPHP DeveloperAuthor 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?
brucegust.com is on GoDaddy
You are sending an email from rodgerstkd.com to brucegust.com - correct?

But GoDaddy is refusing/not connecting.
brucegustPHP DeveloperAuthor Commented:

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.