SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible for a visitor to a page to email a certain part of a page to a friend

    Scenario :

    You have a page where a certain section of that page has text that changes every day at midnight.

    A visitor to that website page sees that particular changing comment and would like to email that text to a friend of theirs. (Without doing any copying and pasting).

    Example of the table layout below.

    Any ideas where to start please?

    Any help very much appreciated.

    Dez.

    <table>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>Changing text here</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not solely with HTML. Something like this would best be done with a server-side language (PHP, JSP, ASP, .NET, ...).
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks - I'll just hop over to the PHP section now.

    Dez.

  4. #4
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    The changing text will be in a database I am guessing..

    Create a form with an email address field at very least.
    Submit to a php script the picks up the email_address submitted by the form and using the mail() function you send the text from the db.

  5. #5
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    Not solely with HTML. Something like this would best be done with a server-side language (PHP, JSP, ASP, .NET, ...).
    Hey . . . . You're not following me, are you Tommy ?

    Dez.

  6. #6
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markbrown4 View Post
    The changing text will be in a database I am guessing..

    Create a form with an email address field at very least.
    Submit to a php script the picks up the email_address submitted by the form and using the mail() function you send the text from the db.
    Hi Mark,

    Thanks for the input - it's appreciated.

    The changing text comes from me, once a day it is changed by me.

    Bearing that in mind Mark, would you still suggest the same thing please ?

    Dez.

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    So how do you change the text? By hand? So its a static html page and you literally change the text and then re-upload the file? If this is the case it makes things a bit more complicated...it would be easier if that text was being pulled from a database...then you could take the root that markbrown suggested.

    let us know as there are solutions!

  8. #8
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Hi,

    You can have your text in a .txt file if you would like.
    It doesn't really matter where the text is as long as it's in it's own location and not embedded into the page.

    You could then use a Server Side Inlcude (SSI) to put the contents of the file into the page, you can also read the contents of the file from PHP and mail them when you submit an email address.

  9. #9
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for coming back to me on this.

    It's definitely embedded into the page.

    Dez.

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    thinking outload here but if you gave the table an id and then used javascript to get the id's contents using getElementById, It might be possible to then send that content to a processing page..........

    hmmm
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ View Post
    thinking outload here but if you gave the table an id and then used javascript to get the id's contents using getElementById, It might be possible to then send that content to a processing page..........

    hmmm
    Sounds good Spike - but as there would be other text in other cells not needed for this, would it be able to get the text from an individual cell ?

    Or, I have been thinking of putting the text in a text file and then, depending on the date, a particular section of text from that text file would automagically be entered into the page, but how could it be done, to ensure that the person emailing, gets that same particular text from that text file please ?

    The helps appreciated.

    Dez.

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    OK have a look at this:
    PHP Code:
    <?php
        print_r
    ($_POST);
    ?>


    <script type="text/javascript">

        function getText() {
            
            var myText = document.getElementById("testText").innerHTML;
            document.emailToFriend.bodyContent.value = myText;
            // alert(myText);
            
        }

    </script>

    <table>
        <tr>
            <td id="testText">my text goes here</td>
        </tr>
    </table>
    <form name="emailToFriend" id="emailToFriend" action="" method="post" />
        <input type="text" name="emailAddress" /><br />
        <input type="hidden" name="bodyContent" />
        <input type="submit" name="test" value="getText" onclick="javascript:getText();" />
    </form>
    It grabs the contents of the table cell with the id testText and puts it into the hidden field of the form. That is then sent through the form as a POST variable which you can then use to email it to the specified address.

    You could then alter the function slightly to allow any cell with an id to be emailed

    Is that what you were after?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    for your second point about getting the data to the page, personally I would use a database to hold your content and display whichever part you need.
    With the function above it takes exactly what is on the screen and send that so whatever you have displayed on a specific day/time is what will be sent.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the following shows some example??
    PHP Code:
    //store this static html and get it from the same
    $html "<table>
                    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
                    <tr><td>&nbsp;</td><td>[CHANGING_TEXT]</td><td>&nbsp;</td></tr>
                    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
                    </table>"
    ;

    //Lets supppose you have your changing text here.
    $changingtext "Something goes here...";

    $toemail $_POST['useremailid']; //user's email id
    $subject "subject goes here";
    $headers "some header information";

    $hody str_replace($changingtext$html$html);

    # then send it to the email
    @mail($toemail$subject$body$headers); 
    The spikez's idea also the great if you can follow it. Before submitting the form you can get some element's innerHTML and store it in some form element. Then post and you can get it with $_POST as other usual text values and send it to the mail.

    Does this make sense??
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    mooving this on slightly you can also amend the script to send different portions of the page, ie different cells....
    PHP Code:
    <?php
        print_r
    ($_POST);
    ?>


    <script type="text/javascript">

        function getText(id) {
            
            var myText = document.getElementById(id).innerHTML;
            document.emailToFriend.bodyContent.value += myText +'|';
            document.getElementById(id).style.color="#FF0000"
            
            
        }

    </script>

    <table>
        <tr>
            <td id="testText" onclick="getText('testText');" style="cursor:hand">my text goes here</td>
        </tr>
        <tr>
            <td id="testText2" onclick="getText('testText2');" style="cursor:hand">my text goes here2</td>
        </tr>
        <tr>
            <td id="testText3" onclick="getText('testText3');" style="cursor:hand">my text goes here3</td>
        </tr>    
    </table>
    <form name="emailToFriend" id="emailToFriend" action="" method="post" />
        <input type="text" name="emailAddress" /><br />
        <input type="hidden" name="bodyContent" />
        <input type="submit" name="test" value="getText" />
    </form>
    creates a pipe | delimited file which can be exploded to get the content

    Edit:


    oh and the text turns red when you click it
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #16
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am 100&#37; agree with your code which is very simple and easy to learn/follow. I am impressed with the idea.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    Thank you rajug
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #18
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks to all who helped on this, especially to SpikeZ and Mark - problem now solved.

    The helps been very much appreciated.

    Dez.

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    No worries Dez
    Just for the benefit of anyone else looking for a similar solution, what did you do in the end to solve the problem?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just using what you kindly mentioned in post 15.

    Thanks again.

    Dez.

  21. #21
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    Thanks Dez for clarifying that
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •