PHP
  Home arrow PHP arrow Page 2 - Coding Folders for a PHP Email Applica...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Coding Folders for a PHP Email Application
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2006-11-15

    Table of Contents:
  • Coding Folders for a PHP Email Application
  • Form Data
  • Explaining Sections B and C
  • The Sent, Trash and Drafts Folders

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Coding Folders for a PHP Email Application - Form Data


    (Page 2 of 4 )

    That is all there is to the form. Next we take a look at the code that will handle the form data:

    <?php

                            session_start();

                            include "connect.php";

                            include("fckeditor/fckeditor.php");

    A

    //retrieve msg from sent folder            

                if(isset($_GET['sid'])){

                $query_msgs = "select * from sent WHERE sent_id =
    '".$_GET['sid']."'";

                $re = mysql_query($query_msgs);

                $n = mysql_num_rows($re);

                $r = mysql_fetch_array($re);

                }

    //retrieve msg from drafts folder         

                if(isset($_GET['did'])){

                $query_msgs = "select * from drafts WHERE draft_id =
    '".$_GET['did']."'";

                $re = mysql_query($query_msgs);

                $n = mysql_num_rows($re);

                $r = mysql_fetch_array($re);

                }

               if(isset($_GET['tid'])){

                $query_msgs = "select * from trash WHERE trash_id =
    '".$_GET['did']."'";

                $re = mysql_query($query_msgs);

                $n = mysql_num_rows($re);

                $r = mysql_fetch_array($re);

                }

    B

               

    //is form submitted

    if(isset($_POST['Submit'])){

    //get login stuff

    $query_email = "SELECT * FROM user WHERE user_id = '".$_SESSION
    ['userid']."'";

                $result_email= mysql_query($query_email);

                $num_email= mysql_num_rows($result_email);

                if($num_email > 0 ){

                while($res = mysql_fetch_array($result_email)){

                $email = $res['email'];

                $user = $res['user_id'];

                $remuser = $res['remuser'];

                $rempass = $res['rempass'];

                $smtp = $res['smtp'];

    }

                }else{

                echo mysql_error();

    }                                  

    include("lib/phpmailer/class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP

    $mail->Host = $smtp;  // specify main and backup server

    $mail->SMTPAuth = true;     // turn on SMTP authentication

    $mail->Username = $remuser;  // SMTP username

    $mail->Password = $rempass; // SMTP password

    //check that the headers are filled

    $from=$_POST['from'];

    $cc=$_POST['cc'];

    $bcc=$_POST['bcc'];

    $to=$_POST['to'];

    $subject=$_POST['sub'];

    $msg=$_POST['msg'];

    //checkbox

    if($_POST['save'] !== ""){

    $query_sent = "INSERT INTO sent SET to = '$to', from =
    '$from',subject = '$subject',";

                $query_sent .= "msg_body = '$msg', userid =
    '".$_SESSION['userid']."',cc ='".$_POST['']."',";      

                $query_sent .="bcc ='".$_POST['bcc']."',date_sent
    =NOW(),attachment = '".$_POST['userfile']."'";

                mysql_query($query_sent);

    }

    // put headers in mail object

    $mail->From = $from;

    $mail->AddAddress($to);

    $mail->AddCC($cc);

    $mail->AddBCC($bcc);

    $mail->Subject = $subject;

    $mail->Body    = $msg;

    $mail->AltBody = $msg;

    $mail->AddReplyTo($from);

    $mailer->ConfirmReadingTo = $from;

    if($_FILES['userfile']['name'] !== ""){

    $mailer->AddAttachment($_FILES['userfile']['tmp_name'], $_FILES
    ['userfile']['name']);

    }

    if(!$mail->Send())

    {

      

       $msg2 =$mail->ErrorInfo;

       header("location:resultpage.php?msg=1&error=$msg2");

       exit;

    }else{

    $msg2="Reply sent to $to";

    header("location:resultpage.php?msg=2&res=$to");

    exit;

    }

    }

    C

    //save as draft

    if(isset($_POST['draft'])){

    $query_draft = "INSERT INTO drafts SET to = '$to', from =
    '$from',subject = '$subject',";

                $query_draft .= "msg_body = '$msg', userid =
    '".$_SESSION['userid']."',cc ='".$_POST['cc']."',"; 

                $query_draft .="bcc ='".$_POST['bcc']."',attachment =
    '".$_POST['userfile']."'";   

                if(mysql_query($query_draft)){

                $msg2="Reply sent to $to";

    header("location:resultpage.php?msg=2&res=$to");

    exit;

                };

    }

    ?>

    The NewMsg.php page will be displayed whenever you click on the Sent, Trash and Draft links that are displayed on all the pages in the application. When you do click on these links, they send a variable to the NewMsg page. The "Sent" link sends a variable called "sid," the "Trash" link sends a variable called "tid" and the "Draft" link sends a variable called "did." Section A of the code above handles these links when it receives those variables. When any of these variables are received, none of the rest of the code is executed.

    More PHP Articles
    More By Leidago


       · Hi Leidago, as I have commented before on the articles about the invoicing system, ...
       · Thank you for your critique, but i'm afraid We are just going into circles on the...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT