Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
if($sql)
{
require("master/PHPMailerAutoload.php");
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "mail.php.net";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "krajesh#php.net";
$mail->Password = "password";
$mail->SetFrom("krajesh#php.net");
$mail->Subject = "subject";
$mail->Body = "<table cellpadding='0' cellspacing='0' border='0' bgcolor='#006699' style='border:solid 10px #006699; width:550px;'>
<tr bgcolor='#006699' height='25'>
<td><img src='logo.jpg' border='0' width='200' height='60' /></td>
</tr>
<tr bgcolor='#FFFFFF'><td> </td></tr>
<tr bgcolor='#FFFFFF' height='30'>
<td valign='top' style='font-family:Arial; font-size:12px; line-height:18px; text-decoration:none; color:#000000; padding-left:20px;'><b> Login details from $website_name </b></td></tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Username : $email </td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Password :$password</td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'><a href='$website_url/index.php?activate=".$actvateid."' style='font-family:Arial; font-size:11px; font-weight:bold; text-decoration:none; color:#2200CC;'>Click Here</a> to activate your account</td>
</tr>
</table>";
$mail->AddAddress($email);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "<script> window.location='index.php?sendsus'; </script>";
exit;
}
}
Did I make a mistake in the code or do I have to change the mailer function itself?
The mail function is working locally, but not working for gmail.. I also tried live but gmail is not working..
You are using wrong host and port number use this code
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->SMTPSecure = "tls";
Related
For some strange reason my PHP login system that sends a confirmation email to activate your account but it doesn't send anything.
<?php
$error = NULL;
require "phpmailer/class.phpmailer.php";
require "phpmailer/class.smtp.php";
require "phpmailer/PHPMailerAutoload.php";
if(isset($_POST['submit'])) {
//Form Data GET
$u = $_POST['u'];
$p = $_POST['p'];
$p2 = $_POST['p2'];
$e = $_POST['e'];
//Throw Username too short error
if(strlen($u) < 5){
$error = "(!) Your username must be at least 5 characters.";
}elseif($p2 != $p) {
//Throw password pair error.
$error .= "(!) Your passwords do not match :/";
}else{
//200 [OK]
//Establish Connection to Database
$mysqli = NEW MySQLi('localhost','root','','test');
//Convert special chars.
$u = $mysqli->real_escape_string($u);
$p = $mysqli->real_escape_string($p);
$p2 = $mysqli->real_escape_string($p2);
$e = $mysqli->real_escape_string($e);
//Generate Verification Key
$vkey = md5(time().$u);
//Insert account into database
$p = md5($p);
$insert = $mysqli->query("INSERT INTO accounts(username,password,email,vkey)
VALUES('$u','$p','$e','$vkey')");
if($insert){
//Start PHPMailer
$mail = new PHPMailer(true);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 0; //No Debug. Set to 3 for verbose logging.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; //Set to SSL to pass checks.
$mail->Host = "smtp.mail.com"; //Set to mail.com server, it has ssl, smtp, and it's free. If you'd like to use gmail, use smtp.gmail.com
$mail->Port = 465; //SSL/TLS Port for mail.com and gmail.com
//FILL WITH YOUR DETAILS
$mail->Username = 'example#mail.com';
$mail->Password = 'example';
//DON'T SET TO SENDER ADDRESS WILL FAIL SPF CHECKS!!!
$mail->SetFrom('example#mail.com', 'example');
$mail->AddAddress($e);
//Send the email.
$mail->Subject = trim("Email Verifcation");
$mail->isHTML(true);
//The Message
$mail->Body = '<h1>Hi, ' . $u . '!</h1><br><p>Activate<br><p>Alternatively copy and paste this link in your browser: <br> <b>Https://localhost' . $vkey . '';
echo "<center><div class='alert success'><strong>Successfully Registered!</strong> Please check your email.</div></center>";
}
//OOPS! Throw $error.
echo $mysqli->error;
}
}
?>
In the beginning, I require the files in my PHPMailer folder, then I start PHPMailer
It stresses me out. Idk the problem. If anybody knows the solution or knows a hint of why it doesn't work that would be great. Thanks.
HTML in same file
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
.alert {
padding: 20px;
background-color: #f44336;
color: white;
opacity: 1;
transition: opacity 0.6s;
margin-bottom: 15px;
font-family: Sans-Serif;
border-radius: 15px;
}
.alert.success {background-color: #4CAF50;}
.alert.info {background-color: #2196F3;}
.alert.warning {background-color: #ff9800;}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
</style>
</head>
<body>
<form method="POST" action="">
<table border="0" align="center" cellpadding="5">
<tr>
<td align="right">Username:</td>
<td><input type="TEXT" name="u" required/></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="PASSWORD" name="p" required/></td>
</tr>
<tr>
<td align="right">Repeat Password</td>
<td><input type="PASSWORD" name="p2" required/></td>
</tr>
<tr>
<td align="right">Email Address</td>
<td><input type="EMAIL" name="e" required/></td>
</tr>
<td colspan="2" align="center"><input type="SUBMIT" name="submit" value="Register" required/></td>
</table>
</form>
<center>
<?php
echo $error ;
?>
</center>
</body>
</html>
you can probably try this
i also had an error so i had to add this line before the host
$mail->SMTPOptions=array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false,'allow_self_signed'=>false));
but if that does not work you can try trobleshooting like this
if($mail->Send()){
}else{
var_dump($mail);
die();
}
so once you get your error logs you can probably do a google or paste your error log and maybe we can help
I'm trying to send emails using PHP Mailer. The site is uploaded to a free hosting. The error is displayed about failed SMTP connection. I'm hoping to someone that has expertise in this matter.
Here goes my code.
require '../extensions/phpmailer/PHPMailerAutoload.php';
$emailAddress = 'SampleEmail';
$password = 'Emailpassword';
$subject = 'Invitation to employee portal';
$message = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Invitation</title>
<body style ="background:#eee;">
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" style ="padding: 40px; max-width:640px;background-color:#f3f3f3;display:block;margin:0 auto; font-family:Lato, sans-serif; color:#626262;font-size:13px;line-height:22px;" width ="600">
<tbody>
<tr>
<td style ="background-color: #3552f2; padding: 34px 122px;">
<h1 width ="600" style ="max-width:600px;width:100%; text-align:center; color:#fff;">HRMS DHVTSU</h1>
</td>
</tr>
<tr>
<td style ="background-color: #ffffff; text-align: center; padding: 40px;">
<h1 style="font-size: 40px; color:#000; font-style: italic;">Sorry your account has been deactivated.</h1>
<br>
<p style ="color:#000; font-size: 16px;">For any questions please contact HR Department.</p>
<br>
<br>
</td>
</tr>
<tr>
<td style ="background-color: #3552f2; text-align: center; font-size: 16px; color: #fff;">
<p>© 2016. All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</body>';
$mail = new PHPMailer;
$mail->isSMTP();
// $mail->SMTPDebug = 2;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $emailAddress;
$mail->Password = $password;
$mail->setFrom('noreply#hrms.com', 'HRMS');
$mail->addReplyTo('johndoe#gmail.com', 'HRMS');
$mail->addAddress($email);
$mail->Subject = $subject;
$mail->msgHTML($message);
if (!$mail->send()) {
// $error = "Mailer Error: " . $mail->ErrorInfo;
// echo '<script>alert("'.$error.'");</script>';
return false;
}else {
$query = 'Update employee_has_credentials set status = '.self::STATUS_INACTIVE.' where id= '.$id.'';
$result = $this->con->prepare($query);
$result->execute(array($id));
if($result->rowCount()){
return true;
}else{
return false;
}
}
Possible duplicate of PHP Mailer issue use that code and it will fix your problem, because you have not added following code:
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php'
or go to above link more description you can see from that answer.
I am unable to generate auto mail on daily bases. The issue is it is not able to generate it automatically. Where as i have a same sort of code which does generates it everyday. With all the same details. The code is exactly same except the database query.
Here is my code:
<?php
session_start();
require("../connect.php");
/* require files for MAIL */
require("class.phpmailer.php");
require("class.smtp.php");
/* require files for MAIL ENDS */
/******** Get the list of audits done in week risk category falls under High Risk and during the previous visit also the location was under High risk category ----mail on every Saturday**********/
$current_date = date('Y-m-d');
//$current_date ='2015-08-22';;
/*$start_time = time() - (6*86400);
$start_dt = date('Y-m-d',$start_time);*/
$pagent_array = array();
$query="Select * from `location_details` ld
Left Join `answer_general_qc` ans_general on ans_general.lid=ld.id
Left Join `audit_general` general on general.qtno = ans_general.qt
Left Join `audit_general_option` general_opt on general_opt.opt_id = ans_general.ans_remark
where ld.completed ='1' and ld.priority != 'qc' and general.qtno ='1' and ans_general.opt = 'no' and
STR_TO_DATE(ld.`date_audited`,'%d-%m-%Y') = '".$current_date."'";
$result=mysql_query($query);
$th_style="border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede";
$td_style="border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff";
$table_result .="<table align='center' rules='all' style='font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #666666;border-collapse: collapse;' border='1';>
<thead>
<tr>
<th style='".$th_style."'>Sr No</th>
<th style='".$th_style."'>Location Code</th>
<th style='".$th_style."'>Location Name</th>
<th style='".$th_style."'>PAgent</th>
<th style='".$th_style."'>Address 1</th>
<th style='".$th_style."'>Address 2</th>
<th style='".$th_style."'>District</th>
<th style='".$th_style."'>State</th>
<th style='".$th_style."'>Priority</th>
<th style='".$th_style."'>Remark by TO</th>
<th style='".$th_style."'>Remark by TO</th>
</tr>
</thead>
<tbody>";
$sr_no=1;
if(mysql_num_rows($result) != 0)
{
while($row=mysql_fetch_array($result))
{
if($row['option_text'] == "")
{
$option_text="Other";
}
else
{
$option_text=$row['option_text'];
}
$table_result .= "
<tr>
<td style='".$td_style."'>".$sr_no."</td>
<td style='".$td_style."'>".$row['location']."</td>
<td style='".$td_style."'>".$row['agent']."</td>
<td style='".$td_style."'>".$row['pagent']."</td>
<td style='".$td_style."'>".$row['address1']."</td>
<td style='".$td_style."'>".$row['address2']."</td>
<td style='".$td_style."'>".$row['district']."</td>
<td style='".$td_style."'>".$row['state']."</td>
<td style='".$td_style."'>".$row['priority']."</td>
<td style='".$td_style."'>".$option_text."</td>
<td style='".$td_style."'>".$row['qc_remark']."</td>
</tr>";
$sr_no++;
}
}
else
{
$table_result .="<tr><td colspan='9' align='center'>No Locations Found</td></tr>";
}
$table_result .="</tbody>
</table>";
// echo $table_result; exit;
/* Code to send MAIL */
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "host";
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->Port = 25;
$mail->Username = "Username";
$mail->Password = "Password";
$mail->From = "From";
$mail->FromName = "Name";
$mail->AddAddress("Email");
$mail->AddBCC("Email CC");
$body = "Dear All,<br /><br />For the review conducted on ".date('d-m-Y',strtotime($current_date))." in the following locations we have found deviation in question 1.1 (ie Does this location exist exactly at the address provided?) <br /><br /><br /><br />";
$body .= $table_result;
$body .= "<br /><br />Warm Regards <br /><br />
Note : Please do not reply to this email as this is an automated mail generated
";
//end body
$mail->IsHTML(true);
//$mail->Subject = "Ref : RC1/HR/".strtoupper($pa)."/".date('F Y',(time()-(5*86400)));
$mail->Subject = "Ref : Lrr 1.1 deviation";
$mail->Body = $body;
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
/* Code to send MAIL Ends */
//mail($to,$subject,$message,$headers);
echo 'Mail sent to '.$pa.'<br /><br />';
/****** END of sending mail **********/
?>
If you want to send mails on a regular or daily basis the ideal way to do that would be to use cron job for sending the mails.By using cron you can specify what application do you want the cron to run on.Also you will be able to specify what time exactly do you want the mail to be sent.
Refer here https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job .
Hope it helps.
I am working on online shopping project.My project works good in my localhost i can checkout and able to receive mail but when i tried to checkout on live server i am getting error :Mailer Error: SMTP connect() failed.Mailer Error: SMTP connect() failed.i am using CakePHP 2.7
This is my function to send mail
public function send_mail($address,$subject,$body)
{
App::import('Vendor', 'mail_class/PHPMailer');
$username="viky.031290#gmail.com";
$password="XXXXXXXX";
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls'; // enable SMTP authentication
$mail->Host = "smtp.gmail.com"; // sets the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = $username; // SMTP account username
$mail->Password = $password; // SMTP account password
$mail->SetFrom($username, 'Orangemart');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($address, "");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
}
This is my checkout function
public function checkout()
{
$this->layout="checkout";
$this->loadModel("Cart");
$cartcount = $this->Cart->find('count',array(
'conditions' => array('public_id' => $this->Session->read("id"))
)
);
$this->set('count', $cartcount);
if(isset($_REQUEST["checkout"]))
{
$this->loadModel("Ordermaster");
$this->loadModel("Cart");
$this->loadModel("Orderdetail");
$this->request->data["date"] = date('y-m-d');
$this->request->data["publics_tbls_id"] = $this->Session->read("id");
$return=$this->Ordermaster->save($this->request->data);
//print_r($return);
$this->Session->write("orderid",$return["Ordermaster"]["id"]);
$dt=$this->Cart->find("all",array("conditions"=>array("public_id"=>$this->Session->read("id"))));
$str="<div class='top' style='height:100px;width:500px;background-color:Orange;color:white'><center><h1 style='padding:25px;font-size:50px';>OrangeMart</h1></center></div>";
$str.="<h3>Detail Order</h3>
<ul>
<li><b>Date:</b>".$return["Ordermaster"]["date"]."</li>
<li><b>Order ID:</b>".$return["Ordermaster"]["id"]."</li>
</ul>";
$str.="<table border='2'>";
$str.="<tr height='50px'>
<td align='center' bgcolor='black'><font color='white'><b>Product Name</b></font></td>
<td align='center' bgcolor='black'><font color='white'><b>Qty</b></font></td>
<td align='center' bgcolor='black'><font color='white'><b>Price</b></font></td>
</tr>";
$subtotal=0;
foreach($dt as $row)
{
$this->request->data["ordermaster_id"]=$return["Ordermaster"]["id"];
$this->request->data["product_tbls_id"]=$row["Cart"]["product_tbls_id"];
$this->request->data["qty"]=$row["Cart"]["qty"];
$this->request->data["psize"]=$row["Cart"]["psize"];
$this->request->data["price"]=$row["product_tbls"]["price"];
$this->Orderdetail->create();
$this->Orderdetail->save($this->request->data);
$str.="<tr height='50px'>";
$str.=" <td align='center'>".$row["product_tbls"]["name"].(($row["Cart"]["psize"]!==Null)?' (Size '.$row["Cart"]["psize"].')':"")./*" (Size ".$row["Cart"]["psize"].")".*/"</td>
<td align='center'>".$row["Cart"]["qty"]."</td>
<td align='center'> Rs. ".$row["Cart"]["price"]."</td>";
$str.="</tr>";
$subtotal=$subtotal+$row["Cart"]["price"];
}
$str.="<tr height='50px'><td colspan='2' align='center' bgcolor='black'><font color='white'><b>SubTotal</b></td><td align='center'><b>".' Rs. '.$subtotal."</b></font></td></tr>
<tr height='50px'><td colspan='2' align='center' bgcolor='black'><font color='white'><b>Payment Method</b></td><td align='center'><b>"."Cash on Delevery"."</b></font></td></tr>";
if($subtotal>2000)
{
$str.="<tr height='50px'><td colspan='2' align='center' bgcolor='black'><font color='white'><b>Shipping Cost</b></td><td align='center'><b>FREE</b></font></td></tr>";
$str.="<tr height='50px'><td colspan='2' align='center' bgcolor='black'><font color='white'><b>Total</b></td><td align='center'><b> Rs. ".$subtotal."</b></font></td></tr>";
}
else
{
$str.="<tr height='50px'><td colspan='2' align='center' bgcolor='black'><font color='white'><b>Shipping Cost</b></td><td align='center'><b> Rs. 99</b></font></td></tr>";
$str.="<tr height='50px'><td colspan='2' align='center' bgcolor='black'><font color='white'><b>Total</b></td><td align='center'><b> Rs. ".($subtotal+99)."</b></font></td></tr>";
}
$str.="</table>";
$str.="</br><ul>
<li><b>Note:</b> ".$return["Ordermaster"]["note"]."</li>
</ul>";
$str.="<h3>Customer details</h3>
<ul>
<li><b>Name:</b> ".$return["Ordermaster"]["name"]."</li>
<li><b>Email:</b> ".$return["Ordermaster"]["email"]."</li>
<li><b>Contact No:</b> ".$return["Ordermaster"]["contact"]."</li>
<li><b>Address:</b> ".$return["Ordermaster"]["address"]."</li>
<li><b>Pincode:</b> ".$return["Ordermaster"]["pincode"]."</li>
</ul>";
$this->send_mail($this->request->data["email"],"OrangeMart",$str);
$this->send_mail("viky.031290#gmail.com","New Order",$str);
$this->Cart->query("delete from cart_tbls where public_id=".$this->Session->read("id"));
$this->redirect("../public/thankyou");
//$this->Session->setFlash(__('My message.'), 'flash_notification');
//$this->Session->setFlash('Successully added to cart!');
}
$this->loadModel("Addcat");
$data = $this->Addcat->find('all');
$this->set('cat', $data);
$this->loadModel("Subcat");
$data = $this->Subcat->query('select * from subcategory_tbls where sub_cat IN ("jeans","T-shirt","dresses","top")');
$this->set('product1', $data);
}
I am creating an e-commerce website that sends email about order detail after user have checked out. I've succeeded in sending email using PHPMailer. However, the content of email I've sent is being escaped.
How do I ensure that the order detail is being processed properly like the image below?
This is the phpmailer code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - SMTP test</title>
</head>
<body>
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set("Asia/Singapore");
require '../PHPMailerAutoload.php';
include ('../test.php');
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";
//enable this if you are using gmail smtp, for mandrill app it is not required
$mail->SMTPSecure = 'ssl';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "GMAIL.COM";
//Password to use for SMTP authentication
$mail->Password = "PASSWORD";
//Set who the message is to be sent from
$mail->setFrom('popo#shop.com', 'POPO ECOMMERCE');
//Set an alternative reply-to address
$mail->addReplyTo('popo#shop.com', 'POPO ECOMMERCE');
//Set who the message is to be sent to
$mail->addAddress($email, $user);
//Set the subject line
$mail->Subject = 'Order Details';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('order.php'), dirname(__FILE__));
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
$mail->XMailer = ' ';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
Message code:
<?php
include("../include/db.php");
$user= $_SESSION['id'];
?>
<?php
echo
"<div style='width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 15px;'>
<h1>Order Details</h1>
";
echo
"<p>Dear <b style='color:blue;'>$user</b>, you have ordered the following products from our website: popo.
Below are the details of your order. We will be shipping the products to your address in two weeks.
<br><br>
Thank you for using POPO.
<Br><br><br>
Order Details: <br></p>";
echo '
<table width = "1093" align="center" bgcolor="silver">
<tr align="center">
<th>S.N</th>
<th>Product ID</th>
<th>Invoice ID</th>
<th>QTY</th>
</tr>';
$get_pro =$db->prepare( 'select Product_ID,invoice_id,qty from orders where userid = ?');
$get_pro->bind_param('s',$user);
$get_pro->execute();
$get_pro->bind_result($pro_title,$pro_id,$pro_qty);
$i =0 ;
while ($get_pro->fetch())
{
$i++;
?>
<?php
echo "
<tr align='center'>
<td> $i</td>
<td> $pro_title</td>
<td> $pro_id</td>
<td>$pro_qty</td>
</tr>";
?>
<?php } ?>
<?php echo "</table>"?>
file_get_content() does not execute php script. You need to replace:
$mail->msgHTML(file_get_contents('order.php'), dirname(__FILE__));
by
ob_start();
include "order.php";
$message = ob_get_clean();
$mail->msgHTML($message);
dont load the order.php with file_get_contents() cause this will not execute the php code!
include the file like this:
ob_start();
include("order.php");
$message = ob_get_contents();
ob_end();
$mail->msgHTML($message);
Try replacing the messege code to this:
<?php
include("../include/db.php");
$user = $_SESSION['id'];
echo "<div style='width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 15px;'>
<h1>Order Details</h1>";
echo "<p>Dear <b style='color:blue;'>$user</b>, you have ordered the following products from our website: popo.
Below are the details of your order. We will be shipping the products to your address in two weeks.
<br>
<br>
Thank you for using POPO.
<Br><br><br>
Order Details: <br></p>";
echo '
<table width = "1093" align="center" bgcolor="silver">
<tr align="center">
<th>S.N</th>
<th>Product ID</th>
<th>Invoice ID</th>
<th>QTY</th>
</tr>';
$get_pro = $db->prepare('select Product_ID,invoice_id,qty from orders where userid = ?');
$get_pro->bind_param('s',$user);
$get_pro->execute();
$get_pro->bind_result($pro_title,$pro_id,$pro_qty);
$i = 0;
while ($get_pro->fetch())
{ $i++;
echo "<tr align='center'>
<td> $i</td>
<td> $pro_title</td>
<td> $pro_id</td>
<td>$pro_qty</td>
</tr>";
break;
}
echo "</table>";
?>
And on the other file:
$mail->msgHTML(file_get_contents('order.php'), dirname(__FILE__));
To:
ob_start();
include("order.php");
$message = ob_get_contents();
ob_end();
$mail->msgHTML($message);