Jasper99 Posted April 7, 2009 Share Posted April 7, 2009 Hey, I don't have a lot of php experience so, please, I need your help: I have a php-script: <?php . . . ?> In this script I want to show a link, something like: <a href="http://www.domain.com/index.html">Hello</a> How can I show a link in a php-script? Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/ Share on other sites More sharing options...
hastishah Posted April 7, 2009 Share Posted April 7, 2009 Hi Just use echo "html tags here"... <?php echo ' <a href="http://www.domain.com/index.html">Hello</a>'; ?> Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803197 Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 If you're building links from the contents of variables you can use this: echo '<a href="'.$url.'">'.$urltext.'</a>'; Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803212 Share on other sites More sharing options...
Axeia Posted April 7, 2009 Share Posted April 7, 2009 Seeing as it's pretty much the most basic thing you can do I suspect you either don't know html, or php. (Can't imagine anyone not knowing html while knowing php though). So you may want to start off with reading some tutorials first, w3schools has excellent tutorials on html and php. Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803214 Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 Agreed - that site Axeia has posted is where I started learning and it's a GREAT resource. Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803217 Share on other sites More sharing options...
Jasper99 Posted April 7, 2009 Author Share Posted April 7, 2009 My be the problem is not soooo basic. It still do not work. My problem: It is a newsletter with a 'tell to a friend' option. After filling out a 'tell to a friend' form an email is send to the 'friend' and it should show the link to the newsletter. What can I do that the link will be shown in the email? As I said the basic script is php. Thanks. Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803225 Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 Can you show the code please? Bit like asking a car mechanic to look at your car while it's still in your garage... Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803229 Share on other sites More sharing options...
Jasper99 Posted April 7, 2009 Author Share Posted April 7, 2009 Here it is out of the garage. Here's the script (tellafriend.php): <?php if(count($_POST)) { foreach(array('fmail1','fmail2','fmail3','email','name') as $key) $_POST[$key] = strip_tags($_POST[$key]); if(!is_secure($_POST)) { die("Hackers begone");} $emailto = "[email protected]"; $esubject = "Recommendation form submission"; $emailtext = " $_POST[name] has used your recommendation form using an email address of $_POST[email] The people the recommendation has been submitted to are: $_POST[fmail1] $_POST[fmail2] $_POST[fmail3] The page recommended: $_POST[refurl] "; @mail("$emailto", $esubject, $emailtext, "From: $_POST[email]"); $thankyoupage = "thankyou.htm"; $tsubject = "A web page recommendation from $_POST[name]"; $ttext = " Hi, $_POST[name], whose email address is $_POST[email] thought you may be interested in this web page. $_POST[refurl] $_POST[name] has used our Tell-a-Friend form to send you this note. We look forward to your visit! "; @mail("$_POST[fmail1],$_POST[fmail2],$_POST[fmail3]", $tsubject, $ttext, "FROM: $_POST[email]"); # After submission, the thank you page header("Location: $thankyoupage"); exit; } function is_secure($ar) { $reg = "/(Content-Type|Bcc|MIME-Version|Content-Transfer-Encoding)/i"; if(!is_array($ar)) { return preg_match($reg,$ar);} $incoming = array_values_recursive($ar); foreach($incoming as $k=>$v) if(preg_match($reg,$v)) return false; return true; } function array_values_recursive($array) { $arrayValues = array(); foreach ($array as $key=>$value) { if (is_scalar($value) || is_resource($value)) { $arrayValues[] = $value; $arrayValues[] = $key; } elseif (is_array($value)) { $arrayValues[] = $key; $arrayValues = array_merge($arrayValues, array_values_recursive($value)); } } return $arrayValues; } ?> Where the code is $_POST[refurl] should be shown the link: The page recommended: $_POST[refurl] and $_POST[name], whose email address is $_POST[email] thought you may be interested in this web page. $_POST[refurl] $_POST[name] has used our Tell-a-Friend form to send you this note. Hope you can help me. Thanks. Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803238 Share on other sites More sharing options...
trq Posted April 7, 2009 Share Posted April 7, 2009 You completely forgot to mention that fact that your sending an email, not displaying a webpage. Emails are designed to be plain text though some email clients can display html. You'll want to look at example #4 on the mail manual page. Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803240 Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 You're wanting the link to appear as a link in an email? Depends on how the client picks it up and translates the body - some will show the link as a link others will show it as text because you're sending a plain text email using PHP's mail() function. A better way would be to download and install the great free PHPMailer script and send a proper HTML email. I've actually stopped using PHP's mail() function and now use PHPMailer instead. http://phpmailer.codeworxtech.com/ Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803244 Share on other sites More sharing options...
Jasper99 Posted April 7, 2009 Author Share Posted April 7, 2009 Yes, it is an email and not a Webpage, sure. But in the code below it shows a link in the email (or at least the link as text). The people the recommendation has been submitted to are: $_POST[fmail1] $_POST[fmail2] $_POST[fmail3] So it must be possible to show the link. It don't have to be a variable. I can change the code for each newsletter. What do you think? Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803260 Share on other sites More sharing options...
trq Posted April 7, 2009 Share Posted April 7, 2009 I think you should actually read the previous replies. No one said it wasn't possible, two solutions have already been posted. Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803262 Share on other sites More sharing options...
Jasper99 Posted April 7, 2009 Author Share Posted April 7, 2009 When I use the solution from hastishah it is still empty, it shows nothing in the email. $_POST[fmail3] The page recommended: "; echo '<a href="http://www.domain.com/index.html">Hello</a>'; @mail("$emailto", $esubject, $emailtext, "From: $_POST[email]"); Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-803270 Share on other sites More sharing options...
hastishah Posted April 8, 2009 Share Posted April 8, 2009 Hi jasper <?php $emailtext = " $_POST[name] has used your recommendation form using an email address of $_POST[email] The people the recommendation has been submitted to are: $_POST[fmail1] $_POST[fmail2] $_POST[fmail3] The page recommended: // if its url like domain.com than <a href='$_POST[refurl]'>$_POST[refurl]</a> // else if url like <a href='link'>domain</a> $_POST[refurl] "; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: '$_POST[email]' . "\r\n"; @mail($emailto, $esubject, $emailtext, $headers); ?> Link to comment https://forums.phpfreaks.com/topic/152937-link-in-php/#findComment-804486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.