PHP
  Home arrow PHP arrow Page 2 - Coding Folders for a PHP Email Application
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT