Home arrow PHP arrow Page 2 - Coding Folders for a PHP Email Application

Form Data - PHP

In this article, the fourth and final one of our series covering the creation of a PHP email application, we are going to look at the code for some of the remaining pages of the mail application. Chief among these is the NewMsg.php page, which is where items, to be more precise, new messages, are either saved as drafts or saved as sent messages.

TABLE OF CONTENTS:
  1. Coding Folders for a PHP Email Application
  2. Form Data
  3. Explaining Sections B and C
  4. The Sent, Trash and Drafts Folders
By: Leidago
Rating: starstarstarstarstar / 8
November 15, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: