Languages :: PHP :: Sending a Link |
|||
| By: tadpole03 |
Date: 19/09/2003 00:00:00 |
Points: 125 | Status: Answered Quality : Excellent |
|
Hi, I'm in the process of writing a 'send to a friend' script but could do with your advice on the actual sending of the link. I'm using the following code at the mo: <? $recipient = "$friendsemail "; $subject = "myTitle"; $mailheaders = "From: myEmail <$youremail>\n"; $mailheaders .= "Reply-To: <$youremail>"; $msg = "$yourname wrote:\n"; $msg .= "$yourmessage\n"; $msg .= "\n"; $msg .= "<A HREF="http://www.myUrl.com\n">http://www.myUrl.com\n</a>"; mail($recipient, $subject, $msg, $mailheaders) or die ("Couldn't send mail!"); ?> The users will be on a page, then click 'Send to a Friend' which will take them to the form page - I obviously want to include a link to the page they've just come from prior to the form. This has to be dynamic as there are many, many different pages. Any help you can give will be greatly appreciated!!!! Tadpole |
|||
| By: akdov | Date: 19/09/2003 02:58:00 | Type : Comment |
|
| Change $msg .= "<A HREF="http://www.myUrl.com\n">http://www.myUrl.com\n</a>"; to $msg .= "<A HREF="http://http://$_SERVER[">http://http://$_SERVER[</a>'HTTP_HOST']$_SERVER['PHP_SELF']"; |
|||
| By: akdov | Date: 19/09/2003 02:59:00 | Type : Comment |
|
| edit: $msg .= "<A HREF="http://$_SERVER[">http://$_SERVER[</a>'HTTP_HOST']$_SERVER['PHP_SELF']" |
|||
| By: tadpole03 | Date: 19/09/2003 03:17:00 | Type : Comment |
|
| Hi, Many thanks for your input. Unfortunately I'm getting an error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' Any ideas? M |
|||
| By: akdov | Date: 19/09/2003 03:30:00 | Type : Comment |
|
| Try taking out the apostrophes. $msg .= "<A HREF="http://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]">http://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]</a>" |
|||
| By: akdov | Date: 19/09/2003 03:33:00 | Type : Comment |
|
| I forgot to add the semicolon at the end, that may be your problem. |
|||
| By: tadpole03 | Date: 19/09/2003 03:50:00 | Type : Comment |
|
| Hi, We're nearly there! Right - there's a link contained in the mail now but it is a link to the actual php script. I need the link to be to the page that the user clicked prior to the form. 1.They see a page they want to send, 2.They click 'Send to a Friend' 3.This opens a page containing the form. Matt |
|||
| By: akdov | Date: 19/09/2003 03:58:00 | Type : Comment |
|
| Ok, try this then. $msg .= "<A HREF="http://$_SERVER[HTTP_REFERER]">http://$_SERVER[HTTP_REFERER]</a>"; |
|||
| By: tadpole03 | Date: 19/09/2003 04:15:00 | Type : Comment |
|
| Ooohhh... how exciting! Nearly done - that sends the link to the form page where as we want the one before that, if you get my meaning? So, the users on the desired page, they click send to a friend which opens a new page with the form on - this is where we're sending them back to at the mo. Would it make a difference if I popped the form in a window then used this script? Many thanks again, Matt |
|||
| By: moseack | Date: 19/09/2003 04:22:00 | Type : Comment |
|
| remove single qoutes inside a "..." syntax: $msg .= "<A HREF="http://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]">http://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]</a>" ; |
|||
| By: moseack | Date: 19/09/2003 04:26:00 | Type : Comment |
|
| add to the form page (which has to be php allso) <input type="hidden" name="ref_url" value="<?php echo $_SERVER[HTTP_REFERER]; ?>"> and to you form procsesing script: $msg .= $ref_url; |
|||
| By: akdov | Date: 19/09/2003 04:27:00 | Type : Comment |
|
| Ah, ok, now I see what you're doing. In the form, you need something like this. <input type="hidden" name="refer" value="<? echo '<A HREF="http://">http://</a>'.$_SERVER[HTTP_REFERER]; ?>" /> That will pull the link from the page you clicked to get there. The in your PHP. $msg .= $refer; |
|||
| By: moseack | Date: 19/09/2003 04:31:00 | Type : Comment |
|
| Funny :) Great mind think alike :) |
|||
| By: akdov | Date: 19/09/2003 04:33:00 | Type : Comment |
|
| I noticed :P |
|||
| By: VGR | Date: 19/09/2003 17:09:00 | Type : Comment |
|
| in case the http_referer isn't set, you could use $script_name.$query_string if ever you still have this problem, I can show you how I did it for a site I have |
|||
| By: tadpole03 | Date: 19/09/2003 17:22:00 | Type : Comment |
|
| Hi, Sorry if I'm being totally dense - now there's no link being returned in the mail! I've saved the form as php itself and added: <input type="hidden" name="ref_url" value="<?php echo $_SERVER[HTTP_REFERER]; ?>"> inside the form. And my php now reads: <? // Configuration of recipient and subject. $recipient = "$friendsemail "; $subject = "mySubject"; $mailheaders = "From: myMail <$youremail>\n"; $mailheaders .= "Reply-To: <$youremail>"; $msg = "$yourname wrote:\n"; $msg .= "$yourmessage\n"; $msg .= "\n"; $msg .= $ref_url; mail($recipient, $subject, $msg, $mailheaders) or die ("Couldn't send mail!"); ?> I'm a little confused! M |
|||
| By: akdov | Date: 19/09/2003 17:26:00 | Type : Comment |
|
| Can you post a link to a page that uses the refer link? |
|||
| By: VGR | Date: 19/09/2003 17:27:00 | Type : Comment |
|
| please read this : <A HREF="http://us4.php.net/manual/en/language.types.array.php">http://us4.php.net/manual/en/language.types.array.php</a> "Array do's and don'ts Why is $foo[bar] wrong? You should always use quotes around a string literal array index." and write this as <input type="hidden" name="ref_url" value="<?php echo $_SERVER['HTTP_REFERER']; ?>"> Anyway, like I said, I doubt this will always work, while using $SCRIPT_NAME or PHP_SELF and QUERY_STRING (or PATH_INFO) always will... |
|||
| By: VGR | Date: 19/09/2003 17:33:00 | Type : Comment |
|
| for instance the link I send via email is : $lienext="{$HTTP_HOST}{$REQUEST_URI}"; // (yes, I've register_globals=On) |
|||
| By: tadpole03 | Date: 19/09/2003 17:41:00 | Type : Comment |
|
| I'm completely lost now, I've tried $msg="{$HTTP_HOST}{$REQUEST_URI}"; in the php but it just returns the recommend.php url. I need the url before the form. Sorry I'm slow at this - I'm a Flash man by trade :) |
|||
| By: VGR | Date: 19/09/2003 17:47:00 | Type : Comment |
|
| at the moment when you build the button "send to a friend" 's link, you add the above "link" as a parameter (urlencoded) towards to "form page". In there you rerieve it, urldecode it, and are ready to send it by email. no ? |
|||
| By: tadpole03 | Date: 19/09/2003 18:02:00 | Type : Comment |
|
| Hi, Thanks for sticking with this! Just to recap, this is where I am at the mo: Step One: HTML page containing this link: <a href="send_pagetest03.php" $lienext="{$HTTP_HOST}{$REQUEST_URI}">sent to a friend </a> Step Two: PHP page with the following form: form name="form1" method="post" action="recommend.php"> <input type="hidden" name="ref_url" value="$lienext"> Your Name: <input type="text" name="yourname"> Your Email: <input type="text" name="youremail"> Friends Email: <input type="text" name="friendsemail"> Your Message: <textarea name="yourmessage"></textarea> <input type="submit" name="Submit2" value="Recommend"> </form> Step Three: PHP Script as follows: <? // Configuration of recipient and subject. $recipient = "$friendsemail "; $subject = "mySubject"; $mailheaders = "From: myEmail <$youremail>\n"; $mailheaders .= "Reply-To: <$youremail>"; $msg = "$yourname wrote:\n"; $msg .= "$yourmessage\n"; $msg .= "\n"; $msg .= $ref_url; mail($recipient, $subject, $msg, $mailheaders) or die ("Couldn't send mail!"); ?> As I've already said, I'm new to this and am trying to get me noggin' around it all! M |
|||
| By: akdov | Date: 19/09/2003 18:07:00 | Type : Assist |
|
| Your HTML is wrong. You can't have a variable like that in HTML. Try: <a href="send_pagetest03.php">sent to a friend </a> Step Two: PHP page with the following form: form name="form1" method="post" action="recommend.php"> <input type="hidden" name="ref_url" value="{$HTTP_HOST}{$REQUEST_URI}"> Your Name: <input type="text" name="yourname"> Your Email: <input type="text" name="youremail"> Friends Email: <input type="text" name="friendsemail"> Your Message: <textarea name="yourmessage"></textarea> <input type="submit" name="Submit2" value="Recommend"> </form> Step Three: PHP Script as follows: <? // Configuration of recipient and subject. $recipient = "$friendsemail "; $subject = "mySubject"; $mailheaders = "From: myEmail <$youremail>\n"; $mailheaders .= "Reply-To: <$youremail>"; $msg = "$yourname wrote:\n"; $msg .= "$yourmessage\n"; $msg .= "\n"; $msg .= $ref_url; mail($recipient, $subject, $msg, $mailheaders) or die ("Couldn't send mail!"); ?> |
|||
| By: VGR | Date: 19/09/2003 18:10:00 | Type : Comment |
|
| it's perfectly correct with two conditions : 1) you've register_globals=On ; else please change the FORM definition (2nd script) using $_GET[] 2) change this : <a href="send_pagetest03.php" $lienext="{$HTTP_HOST}{$REQUEST_URI}">sent to a friend </a> into <a href="send_pagetest03.php?lienext="<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?>">sent to a friend </a> |
|||
| By: tadpole03 | Date: 19/09/2003 18:46:00 | Type : Comment |
|
| Here we go again - can't see what I'm doing wrong boys - it's getting later here in England and I'm going to have to get the lager out in a second as my brain is starting to hurt! Here's what I've got: 1)HTML with this link: <a href="send_pagetest03.php?lienext="<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?>">sent to a friend</a> 2)PHP containing this form: <form name="form1" register_globals=On method="post" action="recommend.php"> <input type="hidden" name="ref_url" value="$lienext"> Your Name: <input type="text" name="yourname"> Your Email: <input type="text" name="youremail"> Friends Email: <input type="text" name="friendsemail"> Your Message: <textarea name="yourmessage"></textarea> <input type="submit" name="Submit2" value="Recommend"> </form> 3)PHP script: <? // Configuration of recipient and subject. $recipient = "$friendsemail "; $subject = "mySubject"; $mailheaders = "From: myEmail <$youremail>\n"; $mailheaders .= "Reply-To: <$youremail>"; $msg = "$yourname wrote:\n"; $msg .= "$yourmessage\n"; $msg .= "\n"; $msg .= $ref_url; mail($recipient, $subject, $msg, $mailheaders) or die ("Couldn't send mail!"); ?> I appologise if I've made any 'school boy' errors - as I say this is all pretty damn new to me! Matt |
|||
| By: tadpole03 | Date: 19/09/2003 18:50:00 | Type : Comment |
|
| All I get as far link is concerend in the mail is: matt wrote: blah blah blah $lienext |
|||
| By: VGR | Date: 19/09/2003 18:55:00 | Type : Comment |
|
| you can't specify "register_globals=On " like you did. This is setup in php.ini and to change it requires you modify the webserver's configuration (php.ini) and relaunch it (or ask it to reload configuration with the -k switch for Apache, for instance) Let's suppose you've register_globals=Off in php.ini (it's more common everyday day). Then modify the second script as follows : <?php $lienext=$_GET['lienext']; ?> <form name="form1" method="post" action="recommend.php"> <input type="hidden" name="ref_url" value="$lienext"> Your Name: <input type="text" name="yourname"> Your Email: <input type="text" name="youremail"> Friends Email: <input type="text" name="friendsemail"> Your Message: <textarea name="yourmessage"></textarea> <input type="submit" name="Submit2" value="Recommend"> </form> and the third one as follows : <? foreach($_POST as $var=>$value) ${$var}=$value; // yes, I know extract() does exist :D // Configuration of recipient... etc ... etc It's late here too :D Even later than for you . Not time to go to the pub, you alcooholic Brit (pleonasm) :D |
|||
| By: VGR | Date: 19/09/2003 18:58:00 | Type : Comment |
|
| oh yes, true. You forgot to echo $lienext I recommend the scripts as : 1)HTML with this link: <a href="send_pagetest03.php?lienext="<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?>">sent to a friend</a> 2)PHP containing this form: <?php $lienext=$_GET['lienext']; echo <<<EOS <form name="form1" method="post" action="recommend.php"> <input type="hidden" name="ref_url" value="$lienext"> Your Name: <input type="text" name="yourname"> Your Email: <input type="text" name="youremail"> Friends Email: <input type="text" name="friendsemail"> Your Message: <textarea name="yourmessage"></textarea> <input type="submit" name="Submit2" value="Recommend"> </form> EOS; ?> 3)PHP script: <? foreach($_POST as $var=>$value) ${$var}=$value; // yes, I know extract() does exist :D // Configuration of recipient and subject. $recipient = "$friendsemail "; $subject = "mySubject"; $mailheaders = "From: myEmail <$youremail>\n"; $mailheaders .= "Reply-To: <$youremail>"; $msg = "$yourname wrote:\n"; $msg .= "$yourmessage\n"; $msg .= "\n"; $msg .= $ref_url; mail($recipient, $subject, $msg, $mailheaders) or die ("Couldn't send mail!"); ?> |
|||
| By: tadpole03 | Date: 19/09/2003 19:17:00 | Type : Comment |
|
| Are you sure the initial line in the HTML is correct? I ask because when I use: <a href="send_pagetest03.php?lienext="<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?>">sent to a friend</a> I get nothing as a link. Where as when I use: <a href="send_pagetest03.php?lienext=<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?>">sent to a friend</a> I get :<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?> as the link in the mail. I'm sure it's nearly there! |
|||
| By: VGR | Date: 19/09/2003 19:38:00 | Type : Assist |
|
| No, leave as before, but you should perhaps use $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] :D |
|||
| By: tadpole03 | Date: 19/09/2003 19:46:00 | Type : Comment |
|
| I think the problem is coming from the HTML to the PHP with form, as after I leave step one the following is in the address bar: <A HREF="http://www.stylefrogcreative.com/build/send_pagetest03.php?lienext=">http://www.stylefrogcreative.com/build/send_pagetest03.php?lienext=</a> Shouldn't this contain the url? M |
|||
| By: tadpole03 | Date: 19/09/2003 20:33:00 | Type : Comment |
|
| Aaaararrrrrgghhh!!! So close yet so far! Any more help/ideas would be greatly appreciated! Cheers, Matt |
|||
| By: moseack | Date: 19/09/2003 20:50:00 | Type : Answer |
|
| Your server probably doesn't parse HTML for PHP code. You can add the needed URL with JavaScript. insted of: <a href="send_pagetest03.php?lienext=<?php echo urlencode($HTTP_HOST.$REQUEST_URI);?>">sent to a friend</a> do <script language="JavaScript"> document.write ("<a href=\"send_pagetest03.php?lienext="+location.href+"\">sent to a friend</a>") </script> |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








