Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: Cannot modify header information 1

Status
Not open for further replies.

BizzyLizzy

Technical User
Nov 3, 2003
77
0
0
AU
Please can somebody help me with this problem. I have had to upload my website again after some problems on the host server. Having done all that I now find that my contact form does not work anymore. I get the following error.

Warning: Cannot modify header information - headers already sent by (output started at /home/intragis/public_html/index.php:8) in /home/intragis/public_html/contact2.php on line 87

I have read the FAQ and have to say that I didnt really understand it :( (lol you may have guessed by now that I am no programmer!).

I have looked for whitespaces and cant see any so I dont think that is the problem.

line 8 of index.php is as follows:-

<META name="keywords" content="GIS viewer, GIS browser, GIS software, maps, mapping, GIS data browser, remote sensing images, ESRI, ECW IntraGIS, enterprise, corporate, TatukGIS, GIS mapping software, GIS, geographic information systems, Web services, Getting Started, executives, IT professionals, developers, education, GIS practictioners, government, new users, GIS.com, desktop GIS, server GIS, developer GIS, mobile GIS, GIS Web services, australia, western, systems"><!--end keywords-->

so I think that could be a red herring.

What I dont understand is why this has suddenly stopped working. I have not changed anything - all I have done is re-upload the site.

If you need me to post the code for the contact form please let me know.

Hoping someone can help.

Cheers Lizzy
 
Thanks very much for that jpadie. Unfortunately, just the same as before works on my test system (ie my laptop running iis!) but as soon as I upload it to the hosters the emails dont come through. It all appears to work ok and redirects ok to the thank you page but the email never gets sent.

What is really bugging me is that this all worked fine just as it was last week. I really really dont get it :(

Just a couple of questions - what are the benefits of using trim? and why is isset better than what I had?


And thank you so much for simplifying that email check bit. lol I always did have a tendancy to overcomplicate things somewhat :)

 
the isset is testing whether the variable exists. you were testing whether the variable is "true" or a loose equivalent of "true". on some setups this will throw a warning if the form has not been submitted. if you use isset to test for form submission (or the presence of any variable) then no error or warning is thrown.

basic rule is "never trust anything a user might do". translated to forms: you should cleanse each input. trim is a very basic cleanse that i do to get rid of white space before writing to a database. some dbs automagically trim white space. in your case, it doesn't really matter as you are just sending the message on by email. i added the trim out of habit.

there is an even neater way to do your form validation, that would use far fewer lines of code - by setting up an array of fields and then iterating the array). you could also consider using a form abstraction layer like quickform to automate the whole task for you.

right ... on to the mail problem. can you try a very simple test to see whether your mail server is a happy chap?

just load a file to your server with the following:
Code:
$email = "knownemailaddress@example.com";
mail ($email, "subject", "message", "From: $email \r\n");
 
Ok done that! Now what?

Actually thinking about it we know the email system is a happy bunny because my registration page is working fine and sending out emails as it should.

 
does the email get through to the known email address?
 
let's have a look at the reg page code for mailing.

also what platform are you using on your server? and do you have any bespoke php.ini 's hanging around in a script directory?

does your provider lock you into using a particular "from " email address?

one other thing: ... have you checked your spam traps?
 
Ok the platform is thus.

Operating system Linux
Kernel version 2.4.21-47.0.1.EL
Machine Type i686
Apache version 1.3.36 (Unix)
PERL version 5.8.4
Path to PERL /usr/bin/perl
Path to sendmail /usr/sbin/sendmail
PHP version 5.1.4

There are no bespoke php.ini files lurking that I can find. We are not locked in to using a particular "from" address either.

the code for the registration page is as follows (dont ask me why as I didnt write it).

Code:
<?php
if ( $_POST['newregister'] ) {

			$today = date("d.m.y");

			// *************************
			// Random Password Generator
			// *************************
			$totalChar = 7; // number of chars in the password
			$salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";  // salt to select chars from
			srand((double)microtime()*1000000); // start the random generator
			$pword=""; // set the inital variable
			for ($i=0;$i<$totalChar;$i++)  // loop and create password
            $pword = $pword . substr ($salt, rand() % strlen($salt), 1);



			function open_db()
			{
				$db = mysql_connect("localhost","root","ma11oy") or die("error"); 
				mysql_select_db("intragis_Contacts",$db); 
			}
			// Insert the email address into the database 
			import_request_variables('p', 'p_'); 
			$realname = "{$p_firstname} {$p_lastname}";
						
			open_db();
			$result = mysql_query("INSERT INTO CONTACTS (EMAIL,PWD,DATE) VALUES ('$p_email','$pword','$today')");
			
			} //endif
							 ?>
<html>
             <td valign="middle" align="center" bgcolor="#FFFFFF"><p align="left">&nbsp;
	</p>
				<form action="index.php?view=thanks" method="post" name="newregister" id="newregister" >                           <div align="left">
						   	<font face="Verdana"><font size="2">
							
							<?php
							echo "<input type=\"hidden\" name=\"firstname\" value=\"{$p_firstname}\">";
							echo "<input type=\"hidden\" name=\"lastname\" value=\"{$p_lastname}\">";
							echo "<input type=\"hidden\" name=\"position\" value=\"{$p_position}\">";
							echo "<input type=\"hidden\" name=\"company\" value=\"{$p_company}\">";
							echo "<input type=\"hidden\" name=\"postaladdress\" value=\"{$p_PostalAddress}\">";
							echo "<input type=\"hidden\" name=\"city\" value=\"{$p_city}\">";
							echo "<input type=\"hidden\" name=\"state\" value=\"{$p_state}\">";
							echo "<input type=\"hidden\" name=\"postcode\" value=\"{$p_postcode}\">";
							echo "<input type=\"hidden\" name=\"country\" value=\"{$p_country}\">";
							echo "<input type=\"hidden\" name=\"phone\" value=\"{$p_phone}\">";
							echo "<input type=\"hidden\" name=\"fax\" value=\"{$p_fax}\">";
							echo "<input type=\"hidden\" name=\"email\" value=\"{$p_email}\">";
							echo "<input type=\"hidden\" name=\"realname\" value=\"{$realname}\">";
							?>
	                         </font>
	                     	 <font size="2">
							 <?php "<input type=\"hidden\" name=\"realname\" value=\"{$realname}\">"; ?>
						     </font></font>
						     <p><font face="Verdana" color="#000080" size="2">Please check your information 
								and press OK. To re-enter the data use your 
								browser's
						         <strong>Back</strong> button.</font></p>
						     <table width="96%" height="279" border="0" cellpadding="4" cellspacing="1">
                               <tr>
                                 <td width="21%" align="right">
									<font face="Verdana" color="#000080" size="2"><strong>First 
									name:</strong></font></td>
                                 <?php echo "<td width=\"71%\" align=\"left\">{$p_firstname}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Last Name:</strong></font></td>
								 <?php echo "<td align=\"left\">{$p_lastname}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Position:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_position}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Company name:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_company}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right"><strong>
									<font face="Verdana" color="#000080" size="2">
									Postal address:</font></strong></td>
                                 <?php echo "<td align=\"left\">{$p_PostalAddress}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>City:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_city}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>State:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_state}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Zip/Postcode:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_postcode}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Country:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_country}</td>"; ?>
                               </tr>
                               <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Telephone:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_phone}</td>"; ?>
                               </tr>
							   <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Fax:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_fax}</td>"; ?>
							   </tr>
							   <tr>
                                 <td align="right">
									<font face="Verdana" color="#000080" size="2"><strong>Email address:</strong></font></td>
                                 <?php echo "<td align=\"left\">{$p_email}</td>"; ?>
							   </tr>
                              
								 <td align="left">&nbsp;</td>
                               </tr>
                               <tr>
                                 <td align="right">&nbsp;</td>
                                 <td align="left">
									<font face="Verdana" color="#000080"><input name="newregister" type="submit" id="newregister" value="OK"></font></td>
                               </tr>
                             </table>
                             <p>&nbsp;</p>
                           </div>
          </form>
	</html>
<?php
$subject2 = "IntraGIS download";
$deptadd2 = "liz@intragis.com.au";

$message2 .= 'firstname: ' . $p_firstname . "\n";
$message2 .= 'lastname: ' . $p_lastname . "\n";
$message2 .= 'position: ' . $p_position . "\n";
$message2 .= 'company: ' . $p_company . "\n";
$message2 .= 'postal Address: ' . $p_PostalAddress . "\n";
$message2 .= 'city: ' . $p_city . "\n";
$message2 .= 'state: ' . $p_state . "\n";
$message2 .= 'postcode: ' . $p_postcode . "\n";
$message2 .= 'country: ' . $p_country . "\n";
$message2 .= 'phone: ' . $p_phone . "\n";
$message2 .= 'fax: ' . $p_fax . "\n";
$message2 .= 'email: ' . $p_email . "\n";



$sendto2 = $deptadd2;
$headers1 = 'From:  <' . $p_email . '>' . "\r\n" . 'Reply-To: ' . $p_email . "\r\n";

mail($sendto2, $subject2, $message2, $headers1);

?>
<?php
$from = "liz@intragis.com.au";
$subject2 = "IntraGIS Registration";

$message3 .= "Dear " .$p_firstname . "\n\n";
$message3 .= "Thank you for registering with IntraGIS Systems. The password to access the download area is " . $pword . ".  
Please note that this password is case sensitive.\n\n
If you encounter any problems or have any questions after installing the demonstration version please don't 
hesitate to contact us at support@intragis.com.au. IntraGIS is designed to be very simple for end-users to use 
but as a first time IntraGIS Application Administrator there is a great deal to learn. We encourage you to work 
through the Administrator's Training Course supplied with the trial system.\n\n
Please note that the trial version installs on a single PC only. If you need to test the software on a full 
client/server setup please contact us on sales@intragis.com.au.\n\n
Regards\n\n
Val Macduff\n
IntraGIS Systems Pty Ltd";

$pwdmail = $email;
$headers2 = 'From:  <' . $from . '>' . "\r\n" . 'Reply-To: ' . $from . "\r\n";

mail($pwdmail, $subject2, $message3, $headers2);

?>

Well this the page that does all the work anyway.

 
if you shove this up in the directory that you are running the other script from, does it work?

Code:
$email = "liz@intragis.com.au";
$result = mail ($email, "test subject", "test message", "From: $email \r\nReturn-Path: $email\r\n");
if ($result === false):
 echo "mail not sent";
else:
 echo "mail submitted to sendmail proc";
endif;
 
ok well I got the mail submitted to sendmail proc message but thus far havent had the email.

I am just testing some other stuff to see whether any emails at all are coming into that address.

In between eating dinner as well :)
 
Ok now this is a bit strange :). I can send emails to the liz@test.com.au address quite happily and they are received. If I do it with the forms I dont get them.

I have changed the email addresses on the registration stuff and all is working fine. Just the liz@test.com.au one not working.

I have just changed the email address on the contact form and that does work. So it looks like there is a problem with that email address but I wonder why it would be just from the forms as I can send and receive email from it outside of the webserver stuff.

 
check the sendmail logs. there might be some useful information in there.
 
Nothing at all in the sendmail logs :( so no help there. I have submitted a support request to our hosters to see if they can see what is wrong with that email address and to check on all the other addresses on our domain as well.

Thank you so much for all your assistance on this. I will let you know how I get on with it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top