Google Answers Logo
View Question
 
Q: web programming ( Answered 4 out of 5 stars,   1 Comment )
Question  
Subject: web programming
Category: Computers > Programming
Asked by: mhffs-ga
List Price: $20.00
Posted: 23 Dec 2002 19:58 PST
Expires: 22 Jan 2003 19:58 PST
Question ID: 132958
I would like to find the code to create a story mailer.  These are
seen on many media sites where you can read the story and mail it to a
friend.
My web host uses php, cgi/perl, mySQL.

Clarification of Question by mhffs-ga on 23 Dec 2002 20:01 PST
An example of a story mailer in use can be seen at www.globeandmail.com
Any story can be viewed and a 'send to a friend' tab is available for each.

Best Regards,
Martin

Request for Question Clarification by joseleon-ga on 24 Dec 2002 10:43 PST
Hello, mhffs:
  Do you want a tailored solution or it's enough for your the story
mailers listed at hotscripts.com? I could create your story mailer
from your MySQL tables in PHP.

Regards.

Clarification of Question by mhffs-ga on 24 Dec 2002 13:28 PST
If it could be customized to include the article in the body of the email: 
ie: select * from Articles where Article_id=3
database 'iact_'
user 'guest'
password 'guestpass'
host 'localhost'

can you do this?
Does $20 cover it?

Request for Question Clarification by joseleon-ga on 25 Dec 2002 01:14 PST
Hello, mhffs:
   I would need the whole table structure, that is the CREATE TABLE
statement, if you provide this, I can develop a script that requests
the user for an e-mail and send the story to that e-mail address. Yes,
$20 cover this. If you want some extra functionality (i.e. Multiple
recipients, send an attachment, HTML mail) we can talk about it.

Regards.
Answer  
Subject: Re: web programming
Answered By: joseleon-ga on 25 Dec 2002 02:41 PST
Rated:4 out of 5 stars
 
Hello, mhffs:
  I have created a base story mailer script that can be adapted to
your table, but in any case, don't hesitate to request for any
clarification to make it fit your needs. To download it, click the
following link:
  
http://www.qadram.com/storymailer.zip

It includes ADOdb, a database abstraction layer I usually use to
access databases, this way, you can change the script to use another
database server (i.e PostgreSQL, Oracle,...) by just changing a single
line of code.

ADOdb
http://phplens.com/lens/dl/adodb290.zip

This is the table I used to design the script:

CREATE TABLE `articles` (
  `article_id` int(13) unsigned NOT NULL auto_increment,
  `article_title` varchar(120) NOT NULL default '',
  `article_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `article_text` text NOT NULL,
  PRIMARY KEY  (`article_id`),
  UNIQUE KEY `article_id` (`article_id`),
  KEY `article_id_2` (`article_id`)
) TYPE=MyISAM;

And here is the script code, but I recommend you to download the whole
version including ADOdb to make it work:

<?php
  //Change this settings to fit your setup
  $db_host='localhost';
  $db_user='root';
  $db_pass='root';
  $database='test';

  //Change this settings to fit your table setup
  $articles_table='articles';
  $article_id='article_id';
  $article_title='article_title';
  $article_date='article_data';
  $article_text='article_text';


  //Database abstraction layer
  include "adodb/adodb.inc.php";
	
  function checkRequiredData()
  {
    $your_name=$_POST['your_name'];
    $your_email=$_POST['your_email'];
    $friend_name=$_POST['friend_name'];
    $friend_email=$_POST['friend_email'];		
						
    if ((empty($your_name)) || (empty($your_email)) ||
(empty($friend_name)) || (empty($friend_email)))
    {
      return(FALSE);
    }
    else return(TRUE);
		
  }
	
  function askRequiredData($msg)
  {
    global $sid;
    global $PHP_SELF;
?>

<form name="mailerform" method="post" action="<?php echo
$PHP_SELF."?action=send&sid=$sid"; ?>">
  <table width="313" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="2"><?php echo $msg; ?><br><br></td>
    </tr>  
    <tr>
      <td width="142">Your name:</td>
      <td width="171"> 
        <input type="text" name="your_name">
      </td>
    </tr>
    <tr>
      <td width="142">Your e-mail:</td>
      <td width="171"> 
        <input type="text" name="your_email">
      </td>
    </tr>
    <tr>
      <td width="142">Your friend's name:</td>
      <td width="171"> 
        <input type="text" name="friend_name">
      </td>
    </tr>
    <tr>
      <td width="142">Your friend's e-mail:</td>
      <td width="171"> 
        <input type="text" name="friend_email">
      </td>
    </tr>
    <tr>
      <td width="142">&nbsp;</td>
      <td width="171">
        <input type="submit" name="Submit" value="Send">
      </td>
    </tr>    
  </table>
</form>

<?php
  }

  if (isset($sid))
  {
    //Connect to the database    
    $articles_db = NewADOConnection('mysql');
    $articles_db->Connect($db_host,$db_user,$db_pass,$database);
		
    //Perform the query
    $sql="select * from $articles_table where $article_id=$sid";
    $rs=$articles_db->Execute($sql);
    if ($rs->RowCount()<=0) die("The requested article don't
exists!!");

    //Extract the data		
    $title=$rs->Fields($article_title);
    $art_date=$rs->Fields($article_date);
    $art_text=$rs->Fields($article_text);
		
    //Change this line to your url, to allow the recipient read the
article online
    $url="http://www.yoursite.com/articles.php?id=$sid";
		
    //The send operation is set
    if ((isset($action)) && ($action=='send'))
    {
      //Check for required data
      $required=checkRequiredData();
      if (!$required)
      {
        //Ask again
        askRequiredData("You must field all the fields!!");
      }
      else
      {
        //Get all the form data
        $your_name=$_POST['your_name'];
        $your_email=$_POST['your_email'];		
        $friend_name=$_POST['friend_name'];		
        $friend_email=$_POST['friend_email'];					

        //Build the message
        $msg="Hello, $friend_name:\n";
        $msg.="\n";
        $msg="Your friend $your_name considered interesting the
following article and wanted to send it to you.\n";
        $msg.="\n";
        $msg.="$title\n";
        $msg.="$art_date\n";
        $msg.="\n";		
        $msg.="$art_text\n";
        $msg.="\n";		
        $msg.="You can read it online at $url\n";
        $msg.="\n";		
        $msg.="Regards.\n";

        //Send mail
        $headers="From: $your_email\r\n"
                ."Reply-To: $your_email\r\n";
				
        if (mail($friend_email, "$your_name sends you this interesting
article", $msg, $headers))
        {
          echo "Mail sent successfully!!";
        }
        else
        {
          echo "There was an error sending mail";
        }
     }
   }
   else
   {
      askRequiredData("You will send the story <b>$title</b> to a
specified friend:");
   }
   
   $articles_db->Disconnect();			
  }
  else
  {
    die ("To use this script, you must provide a Story ID!!");
  }
?>

I hope this is what you need, don't hesitate to request for any
clarification.

Regards.
mhffs-ga rated this answer:4 out of 5 stars
Thank You very much for the detailed answer.  This is exactly what I
was looking for.  Many Thanks,
Martin

Comments  
Subject: Re: web programming
From: bobthedispatcher-ga on 24 Dec 2002 05:29 PST
 
http://hotscripts.com has thousands of links to code for that and all
sorts of other stuff

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy