mrdeleigh Posted November 27, 2006 Share Posted November 27, 2006 HiDoes anyone who a script that can be used in a blog, as a send to a friend (send the page url)Thanksmrdleigh Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/ Share on other sites More sharing options...
The Little Guy Posted November 27, 2006 Share Posted November 27, 2006 there are a couple ways of doing, but one main deal would be this question... do you want to send to only one person, or multiple people? Anther question is... Do you have support for the mail() function? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131039 Share on other sites More sharing options...
mrdeleigh Posted November 27, 2006 Author Share Posted November 27, 2006 Thanks for the reply[quote]do you want to send to only one person, or multiple people?[/quote]multiple if possible but if it is easier with one person i would be happy[quote]Do you have support for the mail() function?[/quote]I use shared hosting so i think soThanksmrdeleigh Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131049 Share on other sites More sharing options...
The Little Guy Posted November 27, 2006 Share Posted November 27, 2006 I haven't tested this yet, so I don't know if you'll get any errors or not.This is the HTML:[code]<form action="somepage.php" method="post">One Email per line<br><textarea name="emails"></textarea><br><input type="submit" name="submit" value="Send"></form>[/code]And here would be the PHP:[code]<?php$email1 = explode("\n",$_POST['emails']);foreach($email1 as $emailaddr){ $email = $emailaddr; $subject = "This Is Your Subject Line"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: ".$_POST['name']." \r\n" . "X-Mailer: PHP/" . phpversion(); $message = '<p>This is your message it can have HTML in it</p>'; $mail = mail($email, $subject, $message, $headers);}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131068 Share on other sites More sharing options...
mrdeleigh Posted November 27, 2006 Author Share Posted November 27, 2006 that work, but i need it to send the url of the page it is on.that will change with each page.can that be done? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131075 Share on other sites More sharing options...
The Little Guy Posted November 27, 2006 Share Posted November 27, 2006 Try this:[code]<?php$email1 = explode("\n",$_POST['emails']);foreach($email1 as $emailaddr){ $email = $emailaddr; $subject = "This Is Your Subject Line"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: ".$_POST['name']." \r\n" . "X-Mailer: PHP/" . phpversion(); $message = '<p>This is your message it can have HTML in it</p><p><a href="http://sitename.com'.$_SERVER['REQUEST_URI'].'">This Site</a></p>'; $mail = mail($email, $subject, $message, $headers);}[/code]?> Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131085 Share on other sites More sharing options...
mrdeleigh Posted November 27, 2006 Author Share Posted November 27, 2006 I.ve put the php in test.php, and the html in test2.phpthe result is giving me domain.com/test.php, i need it to show the test2.php url Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131110 Share on other sites More sharing options...
The Little Guy Posted November 27, 2006 Share Posted November 27, 2006 Try this:[code]<?php$email1 = explode("\n",$_POST['emails']);foreach($email1 as $emailaddr){ $email = $emailaddr; $subject = "This Is Your Subject Line"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: ".$_POST['name']." \r\n" . "X-Mailer: PHP/" . phpversion(); $message = '<p>This is your message it can have HTML in it</p><p><a href="'.$_SERVER['HTTP_REFERER'].'">This Site</a></p>'; $mail = mail($email, $subject, $message, $headers);}[/code] Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131113 Share on other sites More sharing options...
mrdeleigh Posted November 27, 2006 Author Share Posted November 27, 2006 That works great thank..is it possible to put a from box in so when you get the email it has who it is from in the from line of the email and in the body of text XXXXX sent you this link Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131133 Share on other sites More sharing options...
mrdeleigh Posted November 28, 2006 Author Share Posted November 28, 2006 as well as a from box in so when you get the email it has who it is from in the from line of the email and in the body of text XXXXX sent you this link, can it be in a pop up, so when you click on 'send to a friend' the pop you sends the correct link? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-131598 Share on other sites More sharing options...
mrdeleigh Posted November 29, 2006 Author Share Posted November 29, 2006 I just tested this again and it didnt work???does it work for anyone else? the result should email you a link 'this site' but its not with me??? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-132123 Share on other sites More sharing options...
alpine Posted November 30, 2006 Share Posted November 30, 2006 In lack of other responce, here is an example of doing a tipform in a new window.You need to add a javascript function in your head section, then call it upon request (in a link)Like this (remove spaces between[color=blue] s c r i p t[/color]) on line 4:[code]<html><head><s c r i p t type="text/javascript" language="javascript">function open_tip_window(page) {OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=500,height=500");}</script></head><body><?php// article blah blah$art_title = "Article title";?><a href="javascript: open_tip_window('send_tip.php?title=<?php echo $art_title; ?>&url=<?php echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>');" title="Tip a friend">Tip a friend</a></body></html>[/code]The above link opens a new window and that window searches for [color=blue]send_tip.php[/color] and we add a query string containing the article title and the article url, these will be used to fill the form (hidden fields) and continue as post to processing.Also sender email and sender name is added + some very basic minimum validation (included two functions).[b]Study this[/b]:[code]<?phpfunction trim_value(&$value){ $value = trim($value);}function is_email($email){ if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { return true; } else { return false; }}if(isset($_POST['submit'])) // form is posted{foreach($_POST as $name => $value){ ${$name} = strip_tags($value);}if(!empty($from_name) && !empty($from_email) && !empty($to_email)){if(is_email($from_email)){$headers = "From: $from_name <$from_email>\r\n";$headers .= "Reply-To: $from_name <$from_email>\r\n";$headers .= "Return-Path: $from_name <$from_email>\r\n";$headers .= "X-Mailer: PHP v".phpversion()."\r\n";$subject = "Article tip: $title";$message = "Article tip from $from_name ($from_email):\r\n\r\nArticle: $title\r\nURL: $url\r\n\r\n";$to_emails = explode(",", $to_email);array_walk($to_emails, 'trim_value');$no = 0;$report = " emails was sendt:</b><br />";foreach($to_emails as $to_email){if(is_email($to_email)){$mail = mail($to_email, $subject, $message, $headers);if($mail){ $no++; $report .= "<span style=\"color: green\">$to_email</span> OK!<br />";}else{ $report .= "<span style=\"color: red\">$to_email</span> failed...<br />";}}else{ $report .= "<span style=\"color: red\">$to_email</span> not valid email...<br />";}}echo "<b>".$no.$report;}else{echo "Your email is not valid, no mails where sendt";}}else{echo "Not all fields was supplied, no mails where sendt";}}elseif(!empty($_GET['title']) && !empty($_GET['url'])) // show form{echo <<<_HTML<p>Tip a friend, article: <b>{$_GET['title']}</b></p><form method="post" action="send_tip.php"><input type="hidden" name="title" value="{$_GET['title']}" /><input type="hidden" name="url" value="{$_GET['url']}" /><p>Your Name:<br /><input type="text" name="from_name" /></p><p>Your Email:<br /><input type="text" name="from_email" /></p><p>Send to email(s) separated with comma (,):<br /><input type="text" name="to_email" size="60" /></p><p><input type="submit" name="submit" value="Mail IT!" /></p></form>_HTML;}else{ echo "sorry, info missing";}?>[/code]Note that this example uses comma to separate several recipients.Kinda providing you with a working version here, but hopefully you can learn some methods (even if this example isn't perfected) Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-132786 Share on other sites More sharing options...
mrdeleigh Posted December 1, 2006 Author Share Posted December 1, 2006 thanks for the reply i can get the pop up to work? is it working for you?mrdeleigh Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-133317 Share on other sites More sharing options...
mrdeleigh Posted December 3, 2006 Author Share Posted December 3, 2006 did this work for anyone else? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134396 Share on other sites More sharing options...
alpine Posted December 3, 2006 Share Posted December 3, 2006 Probably a blocker, that's the drawback with using pop-ups.I had to disable mine when testing this example, but it works.Try to include it as a .js file instead, strangely enough that seems to help.If not, you will find tonnes of popup examples if you google it. This or another popup script doesn't make a difference. Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134458 Share on other sites More sharing options...
mrdeleigh Posted December 4, 2006 Author Share Posted December 4, 2006 got it working i can trying it in a .html page which didnt work but .php did...i need it in a .htm page can i put the php code in a seperate file? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134750 Share on other sites More sharing options...
alpine Posted December 4, 2006 Share Posted December 4, 2006 Ofcourse it must be a php file - it contains php to handle the title and the mandatory url you want to send - unless you want to sit down and hardcode each and every link and url's ..... ! Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134854 Share on other sites More sharing options...
mrdeleigh Posted December 4, 2006 Author Share Posted December 4, 2006 but is it possible to use a html page and call a php include? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134906 Share on other sites More sharing options...
alpine Posted December 4, 2006 Share Posted December 4, 2006 To call a php include you need to use php - and that means it must be from inside a php file and not a html file.Answer is NO Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134914 Share on other sites More sharing options...
mrdeleigh Posted December 4, 2006 Author Share Posted December 4, 2006 ThanksIf i put a php file in a iframe on the html page is there a way of sending the url of the html page? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134921 Share on other sites More sharing options...
alpine Posted December 4, 2006 Share Posted December 4, 2006 No, you can't.Why on earth can't you name it .php ? ? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134974 Share on other sites More sharing options...
mrdeleigh Posted December 4, 2006 Author Share Posted December 4, 2006 i have changed it to php and the page displays but the function does not work does the php go in after the html? in the body tags? Link to comment https://forums.phpfreaks.com/topic/28633-send-to-a-friend/#findComment-134979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.