My code causes apache to crash....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

My code causes apache to crash....

Post by TiD »

This is the simplified version of the website.
It crashes apache...
If someone can help me out, that would be nice. Even just telling me whether or not this works on their server will help.

People would fill out a form, click submit (form), they double check the details entered on a second page, and if everything is all good, an email button should be there. When they click that email button, the script below is accessed, then apache crashes.

I am able to send the email if i have $message instead of $_POST['relay'] and also, if i have no variables in the mail().
eg. if i have:

$mail = mail("some@email.com", "Statement","Message in a bottle", "From: Somewhere@home.com");

it will send.

Code: Select all

<?php
$message = "Hey World.";

echo "<input type='hidden' name='relay' value='<?$message?>'>";

$mail = mail("$email", "Confy",$_POST&#1111;'relay'], "From: Somewhere@home.com");

if($mail) &#123;
echo "Mail sent";
&#125; else &#123;
echo "Mail not sent";
&#125;
?>
PHP Version: 4.3.3
Display Errors: On
Error Level: E_ALL
Register Globals: Off

Windows Error:
appname: apache.exe
appver: 0.0.0.0
Modname:php4ts.dll
modver: 4.3.3.3
offset: 0009defe[/php_man]
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

Post by Meteo »

I just can't figure out what this line is trying to do...

Code: Select all

echo "<input type='hidden' name='relay' value='<?$message?>'>";
that should be in a form, and the $_POST['relay'] isn't really accessible until the form is submitted, and it's accessible on the page where the form is submitted. here's a little code.

Code: Select all

<?php 

if(isset($_POST['submit'])) {

// form has been submitted

$to = $_POST['address'];
$subject = $_POST['subject'];
$body = $_POST['body'];

$send = mail($to, $subject, $body);
($send == 1) ? $page = 'sending successful' : $page = 'sending unsuccessful';
echo $page;

} else {

// form has not been submitted

$self = $_SERVER['PHP_SELF'];
$form = <<< form
<form method="post" action="$self">
<table>
<tr><td>address</td>
<td><input type="text" name="address"></td>
</tr>tr>
<td>subject</td>
<td><input type="text" name="subject"></td>
</tr><tr>
<td>body</td>
<td><textarea name="body"></td>
</tr><tr>
<td colspan="2"><input type="submit" name="submit" value="send email">
</td>
</tr></table>
</form>
form;
echo $form;
?>
TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

Post by TiD »

Ahhhhh woops.... tried to simplify the code too much. Sorry my mistake.

Code: Select all

// page1.php
<form action="page2.php" method="POST">
<input type="text" name="name1">
<input type="submit" value="<<  Apply  >>">
</form>

Code: Select all

// page2.php
<?
echo "<FORM action='page3.php'>";
echo "Name: $_POST&#1111;'name1']";
echo "<input type="hidden" name="relay" value="'$_POST&#1111;'name']'">";
echo "<INPUT TYPE='submit' VALUE='Submit'>\n";
echo "</form>";
?>
This bit is what's causing apache to crash:

Code: Select all

// page3.php
<?php
$relay = $_POST&#1111;'relay'];
$mail = mail("email@a.com", "Testing", $relay,
     "From: webmaster@hotmail.com");

if($mail) &#123;
echo "Mail sent";
&#125; else &#123;
echo "Mail not sent";
&#125;
?>
Note: I'm quite sure everything works up until it tries to em@il it.

I think my friend called this, the "hidden form" method, or something, if that helps.
Sorry about the confusion, it would be pointless to post my whole site here, i was just trying to trim the fat. I guess i trimmed too much.

Thanks for your time.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok this is just a shot in the dark but this bit here
$mail = mail("email@a.com", "Testing", $relay,
"From: webmaster@hotmail.com");
im assuming its no supposed to be

Code: Select all

$mail = mail("mailto:email@a.com", "Testing", $relay, 
     "From: webmaster@hotmail.com");
right?

there must be seriously something wrong with the code to be crashing apache ive had dozens of errors before and apaches stood strong

and should
"Testing", $relay,
be

Code: Select all

"Testing", "$relay",
?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Just a note: Apache does not run stable under Windows. That is more a Windows issue than an Apache issue.
I know this doesn't help, but if you want a stable environment for Apache, install Linux.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

hmmmmm interesting, more than likely seeing how windows has more problems than any other OS ever

however i run apache under windows and it has never happened to me
TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

Post by TiD »

Malcolmboston: I don't know i've only known PHP for 6 days max, but i tried it, still the crash.

I'm hosting it on my home PC, so as long as you people cannot see any problems with the code, i will host it somewhere and boom! In theory the problem will go away, hopefully....
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

what version pf apache and PHP are you using?

also it may be worth your time defaulting to the original php.ini just incase yu have added any modules that have cabbaged up you server

note: i also have apache running from home (localhost)
TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

Post by TiD »

ph0ar... quick reply.... nice :)

I opened up my logs and found this:
[Fri Jan 23 01:42:16 2004] [error] PHP Notice: Undefined index: relay in *edited directory*\emailscript.php on line 2

Ummm versions? i'm using the latests version of EasyPHP... if that's what you mean...

i haven't touched anything else in php.ini accept smtp, and the other thing under that... i forget... oh yeah sendmail_from

I see.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

give me the first 5 lines of this (only 5 so i know what numbers are which)
Undefined index: relay in *edited directory*\emailscript.php on line 2
first 5 lines of the php file btw

and what the hell does *edited directory* mean?
TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

Post by TiD »

ummmm ignore it, for some reason i didn't want to put my directory in there 5 minutes ago... :?

May as well post the whole thing:

Code: Select all

<?php
$relay = $_POST&#1111;'relay'];
$mail = $mail = mail("mailto:hello@hotmail.com", "Testing", "$relay", 
     "From: webmaster@hotmail.com"); 
if($mail) &#123;
echo "Mail sent";
&#125; else &#123;
echo "Mail not sent";
&#125;
?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

basically apache/php are telling you theres something wrong with this line

Code: Select all

$relay = $_POST['relay'];
are you sure that is the line its saying theres an error? because there isnt
TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

Post by TiD »

Fri Jan 23 02:13:11 2004] [error] PHP Notice: Undefined index: relay in c:\program files\easyphp1-7\www\website\emailscript.php on line 2

It may seem like i'm making this up, but i'm not, i wouldn't waste your time, nor do i want to waste my time.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

i could kind of understand if it was saying undefined constant but it isnt.

ok try

Code: Select all

session_start();
$relay = $_POST[relay'];
or this

Code: Select all

session_start();
$relay = $_POST[relay];
//other method is better
also please check that you have actually got a input named relay on the page before
TiD
Forum Newbie
Posts: 11
Joined: Wed Jan 21, 2004 8:57 am

Post by TiD »

Parse error: parse error, unexpected $end in c:\program files\easyphp1-7\www\website\emailscript.php on line 12
YAY! It didn't crash this time.

although you probably know what you're doing isn't it ment to be:
$_POST['relay'];
as oppossed to:
$_POST[relay'];?

is there much difference between the two?
Post Reply