thebeam Posted May 23, 2006 Share Posted May 23, 2006 All right, here i am again...I have a form, and i want to make one add to it. A friend makes a link to my website's form, and i want to make a source that, when people find and fill the form, by his website, then he will recieve an email, with the name and the email of the person. how can i do that in the PHP file ? And i have to make just one form, becase soon i will migrate to an new batabase system, and making more forms will results in more work in the process of the new system...When ppl submit the form, i recieve an email of the form results. i have to maintaing that... so what can i do ? Link to comment Share on other sites More sharing options...
scott100 Posted May 23, 2006 Share Posted May 23, 2006 fill the form, by his website, then he will recieve an email, with the name and the email of the person. <{POST_SNAPBACK}> This is in the tuts: http://www.w3schools.com/php/php_mail.asp Link to comment Share on other sites More sharing options...
justsomeguy Posted May 23, 2006 Share Posted May 23, 2006 You can set it up so that you have a registry of sites that link to your site. So you could have something like this:test.com email@test.comwww.test.com email@test.commysite.com admin@mysite.comwww.mysite.com admin@mysite.com $sites = array();$site = array();$site['host'] = "test.com";$site['email'] = "email@test.com";$sites[] = $site;$site = array();$site['host'] = "www.test.com";$site['email'] = "email@test.com";$sites[] = $site; etcAnd then when the form loads (before showing the form), you need to check what the referer is: $referer = $_SERVER['HTTP_REFERER']; Parse the URL and figure out what the host is: $chunks = parse_url($referer); Now look up the host in your registry above to figure out which person to email. $to_email = "";for ($i = 0; $i < count($sites); $i++){ if ($sites[$i]['host'] == $chunks['host']) $to_email = $sites[$i]['email'];} Now $email holds the address of the person to send the email to, if the host was found in your list (it might not always be found, so check for empty to address before sending). Include the email address as a hidden form field: <input type="hidden" name="to_email" value="<?php echo $to_email; ?>"> Then when you process the form: $to_address = $_POST['to_email']; Link to comment Share on other sites More sharing options...
thebeam Posted May 24, 2006 Author Share Posted May 24, 2006 This is in the tuts: http://www.w3schools.com/php/php_mail.asp<{POST_SNAPBACK}> Ok, i know that.Justsomeguy understood what i've asked for, thnks.I only have a doubt about the $referer = $_SERVER['HTTP_REFERER'];and$chunks = parse_url($referer);i have to leave like this or put a line to each website and change the "http_referer" and the "parse_url" to the web link? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 24, 2006 Share Posted May 24, 2006 The referer is set automatically by the browser (but is not always reliable). Say you are online at www.mysite.com and you are browsing around. You are located at http://www.mysite.com/links.html or something. You click on a link to http://www.test.com/sweet.html, and when the browser makes the request, the request looks something like this (really simplified):protocol: http 1.1host: www.test.comget: /sweet.htmluser-agent: (browser info, e.g. MSIE 6.0 Windows NT 5.2)referer: http://www.mysite.com/links.htmland a lot more. All of these pieces of info are various HTTP headers, defined by the HTTP spec. This is what it looks like when your browser asks for the page. PHP has access to this stuff through the $_SERVER array. $_SERVER['HTTP_USER_AGENT'] has the user-agent string, $_SERVER['HTTP_REFERER'] has the referer string, etc. So when you read the value of the referer, it will be set by the browser to the address of the page that had the link that you clicked on. If you just typed the address in yourself, the referer is blank.So, you don't have to set the referer, all you do is read it. So anyway, if all you want to do is get the host of the referer (the www.mysite.com part), this is how you extract that part: $referer = $_SERVER['HTTP_REFERER'];$chunks = parse_url($referer);$host = $chunks['host']; Now the $host variable holds the host name, such as "www.mysite.com" or "mysite.com" or whatever it is. This way, you can have an entry for an entire site, regardless of if they have your link on 10 different pages. It will still have the same host name. So you can use that code above at any time to get the host of whoever refered you, if there is one. If $host is empty (""), that means they either typed the address in themselves, or their browser did not specify the referer. Link to comment Share on other sites More sharing options...
thebeam Posted May 24, 2006 Author Share Posted May 24, 2006 oh, now i got it! thanks a lot. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now