For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2005 > mail via html form advice req









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mail via html form advice req
Nick Valeous

2005-02-18, 8:55 pm

Ok, i think this is a very simple task. I decided to do it in the following
way:

I have two files: "\somefolder\contact.htm" which containts the form and
"\somefolder\sendmail.php" which contains the php code. The form POSTs the
data to sendmail.php.In order to check whether there are POSTed data I have
a hidden field (name it "hid"). The php script tests whether the hid value
is set and if not it redirects user to contact.htm. Here is the idea:

<?php
if ($_POST['hid'] != 'laughoutloud') {
// no data posted, lets go back to contact htm:
header('Location: ????contact.htm');
}
else {
// ok lets send the mail
if mail(stuff blah blah) ... print result and redirect after 5 secs
}
?>

My problem is this one: I don't want to use an absolute link in the
redirection (so that if I move sendmail and contact to other folders they
would still work). I only want to redirect to the file contact.htm placed on
the same dir with sendmail.php.If I type:

header('Location: contact.htm');

then the redirection does not work (which is what I expected). If I type

header('Location: http://blah stuff blah/somefolder/contact.htm');

Then if I move the files to somefolder2, redirection will stop working.

I could use 'PHP_SELF' and edit the string, but isn't there a better way to
do this?


Thank you for your time


bonfils

2005-02-19, 8:55 am

"Nick Valeous" <Mouhehe@hehe.com> wrote:

> Ok, i think this is a very simple task. I decided to do it in the
> following
> way:
>
> I have two files: "\somefolder\contact.htm" which containts the form and
> "\somefolder\sendmail.php" which contains the php code. The form POSTs the
> data to sendmail.php.In order to check whether there are POSTed data I
> have
> a hidden field (name it "hid"). The php script tests whether the hid value
> is set and if not it redirects user to contact.htm. Here is the idea:
>
> <?php
> if ($_POST['hid'] != 'laughoutloud') {
> // no data posted, lets go back to contact htm:
> header('Location: ????contact.htm');
> }
> else {
> // ok lets send the mail
> if mail(stuff blah blah) ... print result and redirect after 5 secs
> }
> ?>
>
> My problem is this one: I don't want to use an absolute link in the
> redirection (so that if I move sendmail and contact to other folders they
> would still work). I only want to redirect to the file contact.htm placed
> on
> the same dir with sendmail.php.If I type:
>
> header('Location: contact.htm');
>
> then the redirection does not work (which is what I expected).


Can I ask a stupid newbie question here: Why wouldn't you expect that to
work? I don't believe redirections *have* to be absolute (unless you've
defined a <base href> or something).

--
bonfils
http://kim.bonfils.com


Fat Bloke

2005-02-19, 3:55 pm

>
>Can I ask a stupid newbie question here: Why wouldn't you expect that to
>work? I don't believe redirections *have* to be absolute (unless you've
>defined a <base href> or something).


Also, if you keep the two pages together, it shouldn't be a problem. The
following is the standard stuff I stick in for a Guest Book in my sites.


guest_book.php

<table width=780 cellspacing=0 cellpadding=0 border=0><tr><td><br>

<table width=500 align=center cellspacing=0 cellpadding=8 border=2
bgcolor="#ffffee"><tr><td align=center>Please feel free to make an entry in
our Guest Book - let us know what you think of the website, what you've
learned of XYZ from it, etc, etc</td></tr></table>

<form method=post action="guest_book_add_handle.php">
<table width=580 align=center cellspacing=0 cellpadding=4 border=0>
<tr><td>First name? - <br><input type=text name="firstname"
size=12></td><td>Surname? - <br><input type=text
name="surname"></td></tr><tr><td colspan=2>Your e-mail address? - (this will
<strong>not</strong> be made public)<br><input type=text name="email"
size=60></td></tr>
<tr><td colspan=2>Your comments? - about our website? - about XYZ? - about
you?<br><textarea name="entry" cols=55 rows=8></textarea></td></tr>
<tr><td colspan=2 align=right><input type=submit name="submit"
value="Enter">         <input type=reset name="reset"
value="Clear"> <br>
</td></tr></table>
</form>
</td></tr></table>


guest_book_add_handle.php

<?
if ((!$firstname) || (!$surname) || (!$email) || (!$entry))
{
header("location:guest_book.php");
exit();
}
$date=date("jS F Y");
mail("fatblokeonbike@pinsmothertruckers.co.uk", "Guest book", "New
contribution to the Guest Book - $date.");

Stick the data into the database.
------------------------------------------------------------

This post did not necessarily reflect my opinions. So there.
Pull the pins out to reply direct.
Oli Filth

2005-02-19, 3:55 pm

bonfils wrote:
> Can I ask a stupid newbie question here: Why wouldn't you expect that to
> work? I don't believe redirections *have* to be absolute (unless you've
> defined a <base href> or something).
>


HTTP Location headers must contain an absolute URI. See
http://www.w3.org/Protocols/rfc2616...4.html#sec14.30

Admittedly, it seems some browsers can cope with relative URIs, but this
by no means that you should rely on it.

To the OP, go to http://www.php.net/header. The 5th example down shows
you how to deal with this problem.

--
Oli
Nick Valeous

2005-02-20, 8:55 am

my answer is here: http://www.tipsntutorials.com/tips/PHP/23

basename($PHP_SELF);

simple as that:-)

"Nick Valeous" <Mouhehe@hehe.com> wrote in message
news:cv5j0i$6fj$1@usenet.otenet.gr...
> Ok, i think this is a very simple task. I decided to do it in the

following
> way:
>
> I have two files: "\somefolder\contact.htm" which containts the form and
> "\somefolder\sendmail.php" which contains the php code. The form POSTs the
> data to sendmail.php.In order to check whether there are POSTed data I

have
> a hidden field (name it "hid"). The php script tests whether the hid value
> is set and if not it redirects user to contact.htm. Here is the idea:
>
> <?php
> if ($_POST['hid'] != 'laughoutloud') {
> // no data posted, lets go back to contact htm:
> header('Location: ????contact.htm');
> }
> else {
> // ok lets send the mail
> if mail(stuff blah blah) ... print result and redirect after 5

secs
> }
> ?>
>
> My problem is this one: I don't want to use an absolute link in the
> redirection (so that if I move sendmail and contact to other folders they
> would still work). I only want to redirect to the file contact.htm placed

on
> the same dir with sendmail.php.If I type:
>
> header('Location: contact.htm');
>
> then the redirection does not work (which is what I expected). If I type
>
> header('Location: http://blah stuff blah/somefolder/contact.htm');
>
> Then if I move the files to somefolder2, redirection will stop working.
>
> I could use 'PHP_SELF' and edit the string, but isn't there a better way

to
> do this?
>
>
> Thank you for your time
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com