Hi
I have a code which is using php mail to send emails but i want to change it to use php mailer , I want this piece of code to work like this when the the user click on closed query an email must be sent with a link and if the query is assigned or updated an email must be sent, the code below works perfectly
Can I have two php mailer function like in this code below where i am having two php mail????
pls help me with structuring here is my addresolved.php
<?php
include("connection.php");
// Check if tech is not set
if ($_POST[tech]=="")
{
header("location: indexticket.php");
die();
}
if ($_POST[priority]=="")
$_POST[priority]=2;
// Is record in resolved table
$get="select date_started from resolved where ticket_query=$_POST[ticket]";
$set=mysql_query($get);
$result=mysql_num_rows($set);
$date=mktime(date(H),date(i),date(s),date(m),date(d),date(Y));
// Record exsists
if($result == 1)
{
if ($_POST[status]==1)
$date_f=$date;
else
$date_f="null";
$sql="update resolved set date_finished=$date_f, tech_id=$_POST[tech],";
$sql.=" tech_comment='$_POST[tech_comment]'";
$sql.=" where ticket_query=$_POST[ticket]";
mysql_query($sql);
echo mysql_error();
}
// Record does not exsists
else
{
$date_s=$date;
if ($_POST[status]==1)
$date_f=$date;
else
$date_f="null";
$sql="insert into resolved (ticket_query, tech_id, date_started, date_finished, tech_comment)";
$sql.=" values ($_POST[ticket], $_POST[tech], $date_s, $date_f, '$_POST[tech_comment]')";
mysql_query($sql);
echo mysql_error();
}
// Update the status in the query table
$sql="update query set status=$_POST[status], priority=$_POST[priority], category='$_POST[category]' where ticket=$_POST[ticket]";
mysql_query($sql);
echo mysql_error();
//send email to user if tech marks closed
if ($_POST[status]==1) {
//Get info on technician
$sql="select * from tech where tech_id=$_POST[tech]";
$get=mysql_query($sql);
$result=mysql_fetch_array($get);
// E-mail function
$tic=$_POST[ticket]*1024;
$headers="From: $_POST[useremail]\r\n";
$headers.="Bcc: support1@webmail.co.za\r\n";
$headers.="X-Priority: 1\r\n";
$to="$_POST[useremail]\r\n";
$sub="Close query - Ticket no. $_POST[ticket]";
$msg="Please review and close your query.\r\n";
$msg.="Goto http://10.0.0.7/helpdesk/approval.php?ticket=$tic and please comment on our service.";
mail("$to","$sub","$msg","$headers");
echo mysql_error();
}
else
{
//Get info on technician
$sql="select * from tech where tech_id=$_POST[tech]";
$get=mysql_query($sql);
$result=mysql_fetch_array($get);
// E-mail function
$tic=$_POST[ticket]*1024;
$headers="From: $_POST[useremail]\r\n";
$headers.="Bcc: support1@webmail.co.za\r\n";
$headers.="X-Priority: 1\r\n";
$to="$_POST[useremail]\r\n";
$sub="Update of query - Ticket no. $_POST[ticket]";
$msg="Update from technician.\r\n\n";
$msg.="$_POST[tech_comment]";
mail("$to","$sub","$msg","$headers");
echo mysql_error();
}
header("location: indexticket.php");
die();
?>
my new code llooks like this the message get sent but its show the header information has aleady been sent i cant seem to get the header error right and its really stressing me pls help me out
my new code below
<?php
include("connection.php");
require("class.phpmailer.php");
require("class.smtp.php");
// Check if tech is not set
if ($_POST[tech]=="")
{
header("location: indexticket.php");
die();
}
if ($_POST[priority]=="")
$_POST[priority]=2;
// include("connection.php");
// Is record in resolved table
$get="select date_started from resolved where ticket_query=$_POST[ticket]";
$set=mysql_query($get);
$result=mysql_num_rows($set);
$date=mktime(date(H),date(i),date(s),date(m),date(d),date(Y));
// Record exsists
if($result == 1)
{
if ($_POST[status]==1)
$date_f=$date;
else
$date_f="null";
$sql="update resolved set date_finished=$date_f, tech_id=$_POST[tech],";
$sql.=" tech_comment='$_POST[tech_comment]'";
$sql.=" where ticket_query=$_POST[ticket]";
mysql_query($sql);
echo mysql_error();
}
// Record does not exsists
else
{
$date_s=$date;
if ($_POST[status]==1)
$date_f=$date;
else
$date_f="null";
$sql="insert into resolved (ticket_query, tech_id, date_started, date_finished, tech_comment)";
$sql.=" values ($_POST[ticket], $_POST[tech], $date_s, $date_f, '$_POST[tech_comment]')";
mysql_query($sql);
echo mysql_error();
}
// Update the status in the query table
$sql="update query set status=$_POST[status], priority=$_POST[priority], category='$_POST[category]' where ticket=$_POST[ticket]";
mysql_query($sql);
echo mysql_error();
//send email to user if tech marks closed
if ($_POST[status]==1) {
//Get info on technician
$sql="select * from tech where tech_id=$_POST[tech]";
$get=mysql_query($sql);
$result=mysql_fetch_array($get);
// E-mail function
$tic=$_POST[ticket]*1024;
$headers="From: $_POST[useremail]\r\n";
$headers.="Bcc: support1@webmail.co.za\r\n";
$headers.="X-Priority: 1\r\n";
$to="$_POST[useremail]\r\n";
$sub="Close query - Ticket no. $_POST[ticket]";
$msg="Please review and close your query.\r\n";
$msg.="Goto http://10.0.0.7/helpdesk/approval.php?ticket=$tic and please comment on our service.";
mail("$to","$sub","$msg","$headers");
echo mysql_error();
}
else
{
//Get info on technician
$sql="select * from tech where tech_id=$_POST[tech]";
$get=mysql_query($sql);
$result=mysql_fetch_array($get);
// E-mail function
//$tic=$_POST[ticket]*1024;
$to="$_POST[useremail]\r\n";
$msg="Update of Query.\r\n\n";
$msg.="$_POST[tech_comment]";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "10.0.0.3";
$mail->FromName = "Thikho IT Helpdesk";
$mail->Sender = "\"Thikho IT Helpdesk\" ";
$mail->IsHTML(true);
$mail->From = "From: $_POST[useremail]\r\n";
$mail->AddAddress($to);
$mail->Subject = "Update of query - Ticket no. $_POST[ticket]";
$mail->Body = $msg;
if ($_POST[category] == 'Freightware' || $_POST[category] == 'Freightware Printer'){
$mail->AddAddress("support1@webmail.co.za");
} else {
$mail->AddAddress("support2@webmail.co.za");
}
//$mail->Send and error checking
if(!$mail->Send()) // Now we send the email and check if it was send or not.
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent.';
}
echo mysql_error();
}
header("location: indexticket.php");
die();
?>