Paco
|
| Posted: 02/22/2005, 11:41 AM |
|
Redirect from Login screen when Send Email.
I'm a CCS/PHP rookie having trouble trying to switch to another screen when I click on the Login button on my Login screen. I want to send an email with the username when I click on the Login button and switch to the next screen. The send email part works ok, but I keep getting a warning message
Warning: Cannot modify header information - headers already sent by (output started at D:\Webwork\Practice\test20040913d\login_events.php:46) in D:\Webwork\Practice\test20040913d\login.php on line 306
I used the code from the Quick Start examples as a guide but it appears that according to the warning message, the ECHO and MAIL() functions in the Login_Events.php doesn’t agree with the HEADER() function in the Login.php code.
I’ve browsed thru the forum and noticed comments about a blank line, but I dbl-chkd and don’t have any blank lines in the Login_Events.php code which gets included into the Login.php code.
My Send Email code looks like this:
35//Send Email @18-52131E31
36 global $Login;
37//--- Write your own code here.----------------------
38 $myusername = CCGetUserLogin();
39 $from_name = "FromMe";
40 $from_email = "fromme@myisp.us";
41 $to_email = "toher@herisp.us";
42 $headers = "From: ".$from_name."<".$from_email.">;";
43 $headers .= "Content-Type: text/plain";
44 $subject = "LoggedIn";
45 $message = "User Name=".$myusername." logged in";
46 echo $message;
47 mail($to_email,$subject,$message,$headers);
48 //----- end my own code ----------------------------
49//End Send Email
50
51//Close Login_Button_DoLogin_OnClick @3-0EB5DCFE
52 return $Login_Button_DoLogin_OnClick;
53 }
54//End Close Login_Button_DoLogin_OnClick
and the HEADER code (generated by CCS) looks like this:
296//Execute Components @1-7F070182
297 $Header->Operations();
298 $Login->Operation();
299//End Execute Components
300
301//Go to destination page @1-2B6139F8
302 if($Redirect)
303 {
304 $CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload");
305 $DBConnection1->close();
306 header("Location: " . $Redirect);
307 $Header->Class_Terminate();
308 unset($Header);
309 unset($Login);
310 unset($Tpl);
311 exit;
312}
313//End Go to destination page
314
315//Show Page @1-DC3EEF59
316 $Header->Show("Header");
317 $Login->Show();
318 $Tpl->PParse("main", false);
319//End Show Page
Not sure what I’m doing wrong, can I send an email on the click of the Login button?
My development environment is W2000 Pro, IIS 5.0, CCS 2.3.2.24, MySQL 3.23.49, PHP 4.3.4.
All the CCS stuff I’ve developed so far works ok with no problems. Anyone have any thoughts on what I missed?
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 02/22/2005, 3:03 PM |
|
I think that you should never use "echo" command in your Web application. Only use it for debugging purposes, and then the above error message is OK. I usually get the same error message when debugging Web applications, then I remove the "echo" once I'm done with the debugging part.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
Paco
|
| Posted: 02/22/2005, 3:44 PM |
|
Thanks Peter. Yes, thats all I'm using the echo for is debugging. I've run the same code without the echo in there and it points to the MAIL() and HEADER() functions with the same warning message. once I comment out the MAIL() function everything works and I get the next screen displayed ok. Except then I don't get the email of course.
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 02/22/2005, 3:52 PM |
|
OK, then once you remove the "echo" command then the error message should be little different and it should point to a different line number in the code, like "output started at ... :XX". That's where most likely the problem is.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
klwillis
Posts: 428
|
| Posted: 02/22/2005, 4:22 PM |
|
Try using an HTML redirect statement instead.
Something like this, after you've sent you mail message ...
global $Redirect;
echo ("<meta http-equiv='refresh' content='0;URL=" . $Redirect . "'>");
exit;
_________________
Kevin Willis, VP/CIO
HealthCare Information Technology Specialist
http://www.nexushealthcare.com
"Fast - Convenient - Quality-Care"
Medical Software Consulting Services
Email : klwillis@nexushealthcare.com
Skype : klwillis2006 |
 |
 |
|