boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Email the post to a friend

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Sat Aug 17, 2002 12:06 pm    Post subject: Email the post to a friend Reply with quote

This code will let anyone send the post to a friend via email. It displays a panel with three text fields. The panel is big so you may want to reduce it; edit the table tags or do whatever you want if you know what you are doing.

Put this code inside the b2 loop :

Code:
<form action="sentmail.php3" method="post">
<table border=1 bordercolor="#555555" width="95%" align="center">
<tr><td colspan=2 border=1 align="center"><b>:: Send this post to a friend ::</b></td></tr>
<tr><td width="55">
 >>From:</td><td><input type="text" name="fromemail" size="20"> (your name or email)</td></tr>
<tr><td> >>To:</td><td><input type="text" name="mailto" size="20"> (recipient email)</td></tr>
<tr><td> >>Short message:</td><td><textarea name="msgsender" cols="43" rows="3"></textarea></td></tr>
<tr><td colspan=2 align="right">
<input type=submit name=ok value='send'>
<input type=reset name=reset value='clear'>
</td></tr>
</table>
<input type="hidden" name="postID" value="<?php the_ID() ?>">
<input type="hidden" name="postauthor" value="<?php the_author() ?>">
<input type="hidden" name="authoremail" value="<?php the_author_email() ?>">
</form>




Then, create a new file named sentmail.php3 and save it in the same folder as your blog file. Copy-paste this code in it:

Code:
<?php
include ("blog.header.php");
global $tableposts,$siteurl,$blogfilename;

$get_post=mysql_query("SELECT post_content,post_title,post_date FROM $tableposts WHERE ID='$postID'");
$the_post=mysql_fetch_object($get_post);
$the_post_tx=stripslashes($the_post->post_content);
$subject=stripslashes($the_post->post_title);
$the_date=$the_post->post_date;

$date.=date("l dS of F Y h:i:s A");

if(!preg_match("/^([a-z,0-9,-,_,.])+@([a-z,0-9,-,_,.])+(.([a-z,0-9])+)+$/", $mailto))
{
$error = "<script language=\"javascript\">setTimeout(\"history.go(-1);\",3000);</script><font face=\"verdana\" size=\"2\">There are invalid characters in the <b>recipient e-mail address</b></font></font><br>";
}
if ($error)
{
echo $error;
echo "<br><font face=\"verdana\" size=\"2\">Click back on your browser or wait 3 seconds.</font>.";
exit;
}
if ($error=="")
{
?>
<p><font face="verdana" size="2"><script language="javascript">setTimeout("history.go(-1);",3000);</script><br><br>The post has been sent to <?php echo $mailto ?>.</font></p>
<?
}
$body="Message sent on $date.

From: $fromemail
e-mail: $mailto
-------------------------

Short message from the sender:

==> $msgsender
-------------------------

Author: $postauthor ( $authoremail )
Title: $subject
Date: $the_date
Site: $siteurl/$blogfilename?p=$postID

$the_post_tx
-------------------------";
mail($mailto, $subject, $body, "From: $fromemail X-Mailer: PHP/" . phpversion());
exit;
?>


Enjoy !

Albert Benzer http://benzer.arkania.org
Back to top
View user's profile Send private message Send e-mail
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Sat Aug 17, 2002 1:13 pm    Post subject: Reply with quote

hmm i also created this LOL
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Sat Aug 17, 2002 2:22 pm    Post subject: Reply with quote

GamerZ wrote:
hmm i also created this LOL


So now it has been done twice. xD
Back to top
View user's profile Send private message Send e-mail
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Sat Aug 17, 2002 3:22 pm    Post subject: Reply with quote

Benzer wrote:
GamerZ wrote:
hmm i also created this LOL


So now it has been done twice. xD
LOL, i think urs more complicated. Mine is simple, still noob in php Hehe
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
sami



Joined: 25 Oct 2002
Posts: 21

PostPosted: Wed Jan 29, 2003 7:53 pm    Post subject: putting "email to friend" link at end of article Reply with quote

Hi. My weblog is a collective weblog. The first paragraph of each article posting is shown on the main page, with "more" links to the full articles. I'd like to add an "email this article to a friend" link at the end of the full articles (not at the end of the snippets on the main page). How would I do this?

Thanks,

Sami
Back to top
View user's profile Send private message
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Wed Jan 29, 2003 10:47 pm    Post subject: All you have to do is ... Reply with quote

Make sure the author email and ID are the correct ones and that's it; most likely you won't have to change anything.
_________________
Albert Benzer

[ http://benzer.arkania.org ]
Back to top
View user's profile Send private message Send e-mail
sami



Joined: 25 Oct 2002
Posts: 21

PostPosted: Thu Jan 30, 2003 12:01 am    Post subject: Reply with quote

well, right now the form is appended to the end of the "teasers" of each posting. I'd like the form to only appear at the end of each full posting (which appears when the "more" link is clicked).

sorry, i don't know any php...

sami
Back to top
View user's profile Send private message
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Thu Jan 30, 2003 12:47 am    Post subject: Reply with quote

I see that you are using the same php file to display the list of preview posts and the complete posts. So, all you have to do is to set an "if" statement that will make the "send mail to a friend" function run only if the "more" link is clicked.
You can do this by adding a boolean variable (true/false) that will change when the "more" link is clicked, and the "if" statement will check it.

Dig into code and work it out. Only way to learn.
_________________
Albert Benzer

[ http://benzer.arkania.org ]
Back to top
View user's profile Send private message Send e-mail
sami



Joined: 25 Oct 2002
Posts: 21

PostPosted: Thu Jan 30, 2003 8:14 am    Post subject: Reply with quote

Ok, thank you benzer, I will try what you suggest.
Back to top
View user's profile Send private message
alex_t_king



Joined: 09 Oct 2002
Posts: 194

PostPosted: Fri Jan 31, 2003 1:06 pm    Post subject: Reply with quote

I also created a version of this, mine is in a pop-up window and I did the reg. expression checking of the email address in javascript, client side. Feel free to view source and use or suggest improvements to the client side reg. expression.

in action: http://www.alexking.org/blog/

I added in a very basic little check to make it ever so slightly harder for this to be abused by potential spammers. I hope it isn't an issue - maybe I should have links to open relays for them

I'm using an email class I already had written for another part of my site so I'd have to do some work to package it up right now. Maybe we can merge all of these into a single polished hack.
_________________
Yahoo! Messenger ID: alex_t_king
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
kichu



Joined: 23 Feb 2002
Posts: 53
Location: Chennai,India

PostPosted: Sun Feb 02, 2003 9:47 am    Post subject: Reply with quote

alex_t_king wrote:

I'm using an email class I already had written for another part of my site

Could you please lead me to it!
Thanks
S.K
_________________
Cause something to change, you are not here for ever!
Back to top
View user's profile Send private message Visit poster's website
alex_t_king



Joined: 09 Oct 2002
Posts: 194

PostPosted: Mon Feb 03, 2003 3:28 am    Post subject: Reply with quote

alex_t_king wrote:
I'm using an email class I already had written for another part of my site so I'd have to do some work to package it up right now.


Sorrry for the confusion, what I meant was that this is currently integrated into some other functionality on my web site. I can separate it and package it up separately in a zip file if there is enough demand for it. I'm sure that most PHP savvy folks can use the code Albert has generously provided for us.
_________________
Yahoo! Messenger ID: alex_t_king
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group