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 = $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 = $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 = $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 $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 = $query_sent .= "msg_body = '$msg', userid = $query_sent .="bcc ='".$_POST['bcc']."',date_sent 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 } 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 = $query_draft .= "msg_body = '$msg', userid = $query_draft .="bcc ='".$_POST['bcc']."',attachment = 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.
blog comments powered by Disqus |
|
|
|
|
|
|
|