Php "GET" function

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

Post Reply
polosport6699
Forum Commoner
Posts: 35
Joined: Wed Jun 11, 2003 3:19 pm

Php "GET" function

Post by polosport6699 »

I have been developing a database and I want to have a user fill out a form, then use the "GET" method of posting to send the information to the browser,

Can you have that link automaticly sent to email using a script or mailto:???


This link below is in my browser window. Can i somehow send that value (link) to an email address? Any help is throughly appreaciated
http://localhost/jobcentral/output.php? ... mit=submit
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

yes

Post by phpScott »

Yes you can using a php script that is using mail()
http://ca2.php.net/manual/en/ref.mail.php

phpScott
polosport6699
Forum Commoner
Posts: 35
Joined: Wed Jun 11, 2003 3:19 pm

I know

Post by polosport6699 »

I know that I can send mail using php but I do not know how to get the url address into a variable format to send in the email. Do you understand my dilemma
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

The information submitted by your form will be in the $_POST array, with your <input> names as the keys.

You will need to then concatinate the values in this array and build up your URL, which you could then echo to the browser or mail using the mail() method (as per the reply by phpScott).

Is the intention to allow the recipient of the email to click on the link ??

Or have we lost the plot ;)

Regards,
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Actually, if you use GET the values will be in the $_GET-array.

Use a script like this

Code: Select all

<?php
foreach($_GET as $key=>$value)
   echo "<br>$key = $value";
?>
and assign the values you need to the mail-function .

BUT: using $_GET, especially in this instance where you post emails using GET, is a HUGE security-risk. Everyone could use your script to mass-mail whatever they wanted to.
Try using $_POST - which is somewhat safer (but far from 100%).
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Appologies, I assumed the poster was using POST within the script.

Regards,
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Well, it is safer to use $_POST so it's just that our two posts should be read from the end of the thread to the beginning to make the order of things alright :)
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Very true, and you a spot on, POST is way safer than GET, but that's not to say that any reading this shouldn't use GET. Horses for courses.

:)
polosport6699
Forum Commoner
Posts: 35
Joined: Wed Jun 11, 2003 3:19 pm

Hmmm

Post by polosport6699 »

What would be the code, to go from php form values saying there defined as $value1 $value2 and so on, to emailing thoes values in a clickable link in an auto email
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

You just need to concatinate (glue together) the bits of the $_GET array into a qualified URL:

Code: Select all

$url = "http://".$_GET['DOMAIN']."/".$_GET['FILE']."?x=".$_GET['VAR_X']."&y=".$_GET['VAR_Y']."&z=".$_GET['VAR_Z'];
As dummy data:

Code: Select all

$_GET['DOMAIN']  = "www.devnetwork.net";
$_GET['FILE']        = "index.php";
$_GET['VAR_X']    = "HELLO";
$_GET['VAR_Y']    = "FORUM";
$_GET['VAR_Z']    = "USERS;
Would produce:

http://www.devnetwork.net/index.php?x=H ... UM&z=USERS

As a string in the $url variable, you then need to write this into your message body, as part of the mail() method.

Regards,
Post Reply