Page 1 of 1

URL with parameters/variables and auto emails ?, Lost newbie

Posted: Tue Jun 01, 2004 5:48 am
by Reflexor
The following URL and parameters are used to return a user to my site after making a transaction:

h ttp://www.faststay.com/membersuccess.html?id= ... 3+Red+Road

So how do I use this URL and parameters to run a script that will automatically email the person (in this case george@hotmail.com) and inform him that he successfully joined my site and the password to get in is: members

Can anyone point me in the right direction ? I think php is the best for this but I have no idea how to do it. Please help if you can.

Thanks.

Posted: Tue Jun 01, 2004 6:12 am
by Grim...
The membersuccess.html page will hold the email address in a variable called '$email'.

The following code will send an email out - modify the variables as you see fit.

Code: Select all

$subject = "Welcome To Faststay.com";
$message = "Hello,
Thanks for joining.
Love,
Site Admin";

mail ($email, $subject, $message);
More information on how to make the email more pretty can be found in the php manual: [php_man]mail[/php_man]

Posted: Tue Jun 01, 2004 6:18 am
by Reflexor
How do I implement this ? Can you add php code to a html page or should I change the membersuccess.html page to membersuccess.php page. What needs to be different ? Sorry but I'm clueless with this stuff - its ok if you don't have time to reply :)

Posted: Tue Jun 01, 2004 6:38 am
by mjseaden
Hi Reflexor

You need to make sure your site is PHP hosted (i.e. PHP is installed on your web server). If it is, then you need to change membersuccess.html to membersuccess.php (there is a way to run .html files as .php files if your server is an Apache one, if you know what I'm talking about and you want to do this then it's fairly easy). Changing the extension will make your server recognise your script as a PHP script and run it as one.

As for putting PHP into an HTML file, you generally do it like this:

Code: Select all

?>
<HTML>

<BODY>

<FONT FACE="Tahoma" SIZE="2">This is the HTML part of my script</FONT>

<?php
echo '<FONT FACE="Tahoma" SIZE="2">This is the PHP part of my script.</FONT>';
?>

</BODY>

</HTML>
The '?>' tag turns off PHP and back into HTML. The '<?php' tag turns PHP back on. Note that if you have a '.php' file, it is automatically assumed that all code in it is PHP by your server, and so since I have HTML at the beginning of the above script, I've turned PHP off immediately using '?>' and then back on later using '<?php'.

Hope that helps,

Mark

Posted: Tue Jun 01, 2004 7:06 am
by Reflexor
That is great Mark - thanks for the info, this is making things much clearer.

My hosting server does have php installed so I will use a .php page. Just to clarify though - a .php page can display content like a .html page and also send emails (and do other application type things) this is correct ?

Posted: Tue Jun 01, 2004 7:45 am
by mjseaden
Hi Reflexor,

A PHP script can comprise of both HTML and PHP - infact it can even comprise of other languages such as JavaScript. Here's an example:

Code: Select all

echo '<A HREF="http://www.domain.com" onmouseclick="JavaScript: function();">Link Text</A>';
If you were to run this script on your browser, and then click 'View Source' you would just see

Code: Select all

&lt;A HREF="http://www.domain.com" onmouseclick="JavaScript: function();"&gt;Link Text&lt;/A&gt;
In other words, you have used PHP's echo command to output HTML and JavaScript to your browser. The PHP doesn't show up when you click 'View Source', because all PHP's doings occur before the pages are sent to the client (the person using a browser to look at your site). This is why PHP is called a 'server side' language (all processing occurs on your web server and is _then_ sent to the client - the client doesn't do any processing) as contrasted with a 'client side' language such as HTML (your browser interprets HTML and displays your page accordingly - hence it is a 'client side' language) and also JavaScript, which is also run by the browser.

Easy.

Mark

Posted: Tue Jun 01, 2004 7:48 am
by Grim...
mjseaden wrote:...it is automatically assumed that all code in it is PHP by your server...
Really?

Posted: Tue Jun 01, 2004 7:50 am
by mjseaden
....in that you have to turn PHP processing off using '?>' in order to use bare HTML. That doesn't mean for instance that you can't output other languages using PHP if you for instance use 'echo'.

Posted: Tue Jun 01, 2004 7:56 am
by Weirdan
http://php.net/manual/en/language.basic-syntax.php
PHP Manual wrote: When PHP parses a file, it simply passes the text of the file through until it encounters one of the special tags which tell it to start interpreting the text as PHP code. The parser then executes all the code it finds, up until it runs into a PHP closing tag, which tells the parser to just start passing the text through again. This is the mechanism which allows you to embed PHP code inside HTML: everything outside the PHP tags is left utterly alone, while everything inside is parsed as code.
You don't have 'to turn PHP processing off'.

Posted: Tue Jun 01, 2004 7:59 am
by mjseaden
Weirdan - If I used

Code: Select all

<Files myfile.html>
ForceType application/x-httpd-php (or similar line, can't remember exactly what)
</Files>
In my .htaccess for my server, then the PHP interpreter would be turned on for this particular file. Otherwise it would be treated as HTML and <?php ?> tags would just be treated as text. Is that not right? Otherwise PHP wouldn't be parsing the file in the first place? Pretty useful for me to know the exact answer to this question.

Mark

Posted: Tue Jun 01, 2004 8:00 am
by mjseaden
Yeah I get what you mean - in other words I was wrong, you don't need '?>' at the beginning of the PHP file, you need to turn it on using <?php tag. I should know that as that's what I've always been doing!

Mark

Posted: Tue Jun 01, 2004 8:10 am
by Weirdan
Exactly ;)