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

Posted on 2014-08-15
Last Modified: 2014-09-10
The following script is an email thing that sends the user their password info. It works on my server on, but it doesn't do anything on No errors, mind you, just no email.

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

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: <>' . "\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:\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?
Question by:brucegust
    LVL 58

    Accepted Solution

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

    Assisted Solution

    Agree with Gary - mail probably isn't configured on ''.

    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 = '\nCC:,,'

    Open in new window

    LVL 21

    Assisted Solution

    by:Randy Poole
    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.

    Author Comment

    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 bizsmtp ESMTP server ready
    ehlo hello [], pleased to meet you
    250-SIZE 104857600
    250 OK
    mail from:
    250 2.1.0 <> sender ok
    rcpt to:
    250 2.1.5 <> 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 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. 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=<>, relay=apache@localhost
    Aug 15 08:45:31 web sendmail[29933]: s7FDjLGn029933: from=<>, size=475, class=0, nrcpts=1, msgid=<>, proto=ESMTP, daemon=MTA, relay=localhost []
    Aug 15 08:45:31 web sendmail[29932]: s7FDjLuA029932:, 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=<>, ctladdr=<> (48/48), delay=00:00:06, xdelay=00:00:06, mailer=esmtp, pri=120443, [], dsn=5.0.0, stat=Service unavailable
    Aug 15 08:08:14 web sendmail[29907]: s7FD88Yl029907:, 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=<>, ctladdr=<> (48/48), delay=00:00:07, xdelay=00:00:07, mailer=esmtp, pri=120467, [], dsn=5.0.0, stat=Service unavailable
    Aug 15 08:45:31 web sendmail[29932]: s7FDjLuA029932:, 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=<>, ctladdr=<> (48/48), delay=00:00:07, xdelay=00:00:02, mailer=esmtp, pri=120475, [], 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?
    LVL 58

    Expert Comment

    You're on GoDaddy - groan.

    Are you sure you have your SMTP/Email setup corretly?

    Author Comment

    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?
    LVL 58

    Expert Comment

    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!

    Author Comment

    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 (
    - password_send.php fires just fine on my server (
    - there are no errors on the password_send.php when we run it from
    - he attempts to trouble shoot my using a command line approach that sends an email from his server to
    - the email he sends doesn't arrive at which suggests that something is wrong on godaddy
    - I suggest that he try to run a scenario from using his login information. He does and the email arrives fine at

    Having just got off the phone with godaddy and relayed the "Service unavailable" error to them when a person attempted to email me at, 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?
    LVL 58

    Expert Comment

    by:Gary is on GoDaddy
    You are sending an email from to - correct?

    But GoDaddy is refusing/not connecting.

    Author Comment


    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 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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now