PHP/HTML Excel export button - php

I need to make a button which when clicked, will export all data from the HTML form on the page to an excel file. Could anyone help me with this I'm new to PHP and dont know where to begin.
<div class="left col-md-12 form-group" >
<form method="post" id="triallesson_form">
<div class="table">
<table class="table table-header-rotated table-condensed table-striped table-hover" style="width: 100%;">
<th></th>
<th class="col-xs-1 not-rotate"><div><span><?= text::$string['person_name'] ;?></span></div> </th>
<th class="col-xs-1 not-rotate"><div><span><?= text::$string['person_telphone'] ;?></span></div> </th>
<th class="col-xs-1 not-rotate"><div><span><?= text::$string['location_name'] ;?></span></div> </th>
<th class="col-xs-3 not-rotate"><div><span><?= text::$string['class_date'] ;?></span></div> </th>
<th class="col-xs-2 not-rotate"><div><span><?= text::$string['triallesson_type'] ;?></span></div> </th>
<th class="col-xs-2 not-rotate"><div><span><?= text::$string['triallesson_email'] ;?></span></div> </th>
<th class="col-xs-2 not-rotate"><div><span>via</span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_called'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_confirmd'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_show'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_sign_up'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_cancelled'] ;?></span></div> </th>
<th class="rotate-45" title="<?= Text::$string['triallesson_sms_info'];?>"><div><span><?= Text::$string['triallesson_sms'] ;?></span></div> </th>
<th></th>
<?= $content[1]; ?>
</table>
<input type="hidden" name="date1" value="<?=$con->date1?>">
<input type="hidden" name="date2" value="<?=$con->date2?>"></form>
</div>
</div>
Last time I didnt add the code sorry.
This is the table where my data will be showed in.
My intention is that when I click a button on the same page, it will take all the data from the table and export it into a XLS or CSV file.
If any further information is needed I'll add it, thankyou in advance.

You're using PHP to create the table but it might be simpler to use JavaScript to create the Excel file from the resultant HTML table as there are a variety of tools available to do this which are not too hard to use, such as: https://github.com/clarketm/TableExport
e.g. Using this as an example: https://tableexport.v3.travismclarke.com/examples/position.html for your table your code could look like this:
<div class="left col-md-12 form-group" >
<form method="post" id="triallesson_form">
<div class="table">
<table id="myDataTable" class="table table-header-rotated table-condensed table-striped table-hover" style="width: 100%;">
<thead>
<th></th>
<th class="col-xs-1 not-rotate"><div><span><?= text::$string['person_name'] ;?></span></div> </th>
<th class="col-xs-1 not-rotate"><div><span><?= text::$string['person_telphone'] ;?></span></div> </th>
<th class="col-xs-1 not-rotate"><div><span><?= text::$string['location_name'] ;?></span></div> </th>
<th class="col-xs-3 not-rotate"><div><span><?= text::$string['class_date'] ;?></span></div> </th>
<th class="col-xs-2 not-rotate"><div><span><?= text::$string['triallesson_type'] ;?></span></div> </th>
<th class="col-xs-2 not-rotate"><div><span><?= text::$string['triallesson_email'] ;?></span></div> </th>
<th class="col-xs-2 not-rotate"><div><span>via</span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_called'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_confirmd'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_show'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_sign_up'] ;?></span></div> </th>
<th class="rotate-45"><div><span><?= text::$string['triallesson_cancelled'] ;?></span></div> </th>
<th class="rotate-45" title="<?= Text::$string['triallesson_sms_info'];?>"><div><span><?= Text::$string['triallesson_sms'] ;?></span></div> </th>
<th></th>
</thead>
<tbody>
<?= $content[1]; ?>
</tbody>
</table>
<input type="hidden" name="date1" value="<?=$con->date1?>">
<input type="hidden" name="date2" value="<?=$con->date2?>">
</div>
</form>
</div>
<script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../bower_components/js-xlsx/dist/xlsx.core.min.js"></script>
<script type="text/javascript" src="../bower_components/blobjs/Blob.min.js"></script>
<script type="text/javascript" src="../bower_components/file-saverjs/FileSaver.min.js"></script>
<script type="text/javascript" src="../dist/js/tableexport.min.js"></script>
<script>
var PositionTable = document.getElementById('myDataTable');
new TableExport(PositionTable, {
position: 'top'
});
</script>
The only necessary change made to your HTML is adding an ID attribute to the table: <table id="myDataTable" ...
That's then referenced again in the JavaScript lower down: var PositionTable = document.getElementById('myDataTable');.
You'll need to update the locations of the included files to fit where you've got them (xlsx.core.min.js, Blob.min.js, FileSaver.min.js, tableexport.min.js, etc.). Remove the jQuery include if unneeded.
You'll then see Excel download buttons appear under your table just like in the example.

Related

how to download pdf for a line from a table in laravel

i want to generate pdf from the database for 1 row in a table , the table name is "listings"
i used that script for the controller :
class CreatePdfController extends Controller
{
public function pdfForm(Request $request,$id){
$listing = Listing::findOrFail($id);
view()->share('listing',$listing);
if($request->has('download')){
$pdf = PDF::loadView('pdf_download');
return $pdf->download('pdf_download.pdf');
}
return view('show_details')->with('listing', $listing);
}
}
and for the show_details its the view where can i fetch just the data for 1 line in the table :
<div class="col-sm-8 offset-sm-2">
Download PDF
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header col-xs-6">
<div class="col-xs-3">
<h2>Listing Ref n° :{{$listing->id}}</h2>
{{$listing->owner->owner_lastname}}</h4>
</div>
<div class="col-xs-3">
<img src="{{ asset('/assets/images/listings/'.$listing->listing_Fimage) }}" width="120px" height="100px" alt="image" >
</div>
</div>
<div class="card-body">
<div class="col-xs-7 well">
<table id="example1" class="table table-bordered">
<thead>
<tr>
<th scope="row">listing_title:</th>
<td>{{$listing->listing_title}}</td>
</tr>
<tr>
<th scope="row">listing_type:</th>
<td>{{$listing->listing_type}}</td>
</tr>
<tr>
<th scope="row">listing_purpose:</th>
<td>{{$listing->listing_purpose}}</td>
</tr>
<tr>
<th scope="row">listing_location:</th>
<td>{{$listing->listing_location}}</td>
</tr>
<tr>
the pdf_download is the view that i want to generated as pdf :
<table id="example1" class="table table-bordered">
<thead>
<tr>
<th scope="row">listing_title:</th>
<td>{{$listing->listing_title}}</td>
</tr>
<tr>
<th scope="row">listing_type:</th>
<td>{{$listing->listing_type}}</td>
</tr>
<tr>
<th scope="row">listing_purpose:</th>
<td>{{$listing->listing_purpose}}</td>
</tr>
<tr>
<th scope="row">listing_location:</th>
<td>{{$listing->listing_location}}</td>
</tr>
<tr>
<th scope="row">listing_emirate:</th>
<td>{{$listing->listing_emirate}}</td>
</tr>
<tr>
<th scope="row">listing_community:</th>
<td>{{$listing->listing_community}}</td>
</tr>
<tr>
<th scope="row">listing_price:</th>
<td>{{$listing->listing_price}}</td>
</tr>
</table>
and the route that i passed is :
Route::get('/show_details/{id}' ,array('as'=>'show_details',
'uses'=>'CreatePdfController#pdfForm'));
the problem is i get that error and i cannot download the pdf file :
**Symfony\Component\ErrorHandler\Error\FatalError
Maximum execution time of 60 seconds exceeded
http://127.0.0.1:8000/show_details/3?download=pdf**

Shop by size using table format in PHP

I want my site to search for any product that belonged to particular size when click any size option in the table cell for desktop users but I am having two challenges
My loop for horizontal cells suppose to be incrementing from left to right like this 28D, 28DD, 28E, 28F, 28FF, 28G ...28K and then move to second line 30D --- 30k but instead it was reapeating each value 12 times horizontally like this 28D, 28D, 28D 12times and move to second line 28DD repeating it 12 times again. Please what could be the problem in my four loop?
I don't know how to put anchor tag around the table cell and how to put name = size attribute in the table cell for it to link sizeresult.php. where it will be processed by the select query
here is my code:
<div class="table-responsive"><!-- table-responsive begin -->
<table class="table table-striped table-hover" border="0" width="100%" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th class="success">
<h4 class="text-center white-text">D</h4>
</th>
<th class="info">
<h4 class="text-center white-text">DD</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">E</h4>
</th>
<th class="success">
<h4 class="text-center white-text">F</h4>
</th>
<th class="info">
<h4 class="text-center white-text">FF</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">G</h4>
</th>
<th class="success">
<h4 class="text-center white-text">GG</h4>
</th>
<th class="info">
<h4 class="text-center white-text">H</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">HH</h4>
</th>
<th class="success">
<h4 class="text-center white-text">J</h4>
</th>
<th class="info">
<h4 class="text-center white-text">JJ</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">K</h4>
</th>
</tr>
</thead>
<tbody>
<?php
$count = 12; // Number of possible cells to add at once:
$i=0;
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($dbc,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size_name = $row_sizes['size'];
$i++;
?>
<tr>
<?php for ($i = 1; $i <= $count; $i++) {
echo "
<td value='$size_name' align='center'>
$size_name
</td>";
} // End of FOR loop.
?>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- table-responsive end -->
</form>
sizeresult.php code is this :
$size_name=$_POST['size'];
$run_products = mysqli_query($dbc,"SELECT * FROM products INNER JOIN SIZES USING (size_id) WHERE sizes.size ='%$size_name%'");
I made the following changes
$count variable and for loop completely
created block of code to format your list of items in the way you have explained in your question grouping them by 12 in each row.
based on your request of using anchor tag i added anchor tag so that when the user clicks on it it will be taken to the sizeresult.php page and the query will be processed.
I made sure that the post and get request doesn't conflict by putting the following code right above the query in sizeresult.php
if(isset($_GET['size'])){ $size_name=$_GET['size'] } else if(isset($_POST['size'])){ $size_name=$_POST['size']; }
the following in your main page
<div class="table-responsive"><!-- table-responsive begin -->
<table class="table table-striped table-hover" border="0" width="100%" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th class="success">
<h4 class="text-center white-text">D</h4>
</th>
<th class="info">
<h4 class="text-center white-text">DD</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">E</h4>
</th>
<th class="success">
<h4 class="text-center white-text">F</h4>
</th>
<th class="info">
<h4 class="text-center white-text">FF</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">G</h4>
</th>
<th class="success">
<h4 class="text-center white-text">GG</h4>
</th>
<th class="info">
<h4 class="text-center white-text">H</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">HH</h4>
</th>
<th class="success">
<h4 class="text-center white-text">J</h4>
</th>
<th class="info">
<h4 class="text-center white-text">JJ</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">K</h4>
</th>
</tr>
</thead>
<tbody>
<tr>
<?php
//$count = 12; // Number of possible cells to add at once://you don't need this too.
$i=1;
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($dbc,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size_name = $row_sizes['size'];
if($i==12){
echo "<td align='center'><a href='product-card.php?size=$size_name' type='button' style='text-decoration:none; color:black;' class='btn btn-block'>$size_name</a></td>";
$i=1;
echo "</tr><tr>";
}
else {
echo "<td align='center'><a href='product-card.php?size=$size_name' type='button' style='text-decoration:none; color:black;' class='btn btn-block'>$size_name</a></td>";
$i++;
}
} // End of while loop.
?>
</tr>
</tbody>
</table>
</div> <!-- table-responsive end -->
<!-- </form> you can remove this FORM tag if you want -->

Hide a column in datatable

i have a question where i want to hide the column in datatable but still need to access its value.
this is my code
<div class="container">
<div class="">
<h1>HRphn</h1>
<div class="col-sm-8">
<div class="well clearfix">
<div class="pull-right"><button type="button" class="btn btn-xs btn-primary" id="command-add" data-row-id="0">
<span class="glyphicon glyphicon-plus"></span> Record</button></div></div>
<table id="posting_grid" class="table table-condensed table-hover table-striped" width="60%" cellspacing="0" data-toggle="bootgrid">
<thead>
<tr>
<th data-column-id="id" data-type="numeric" data-identifier="true">Posting No</th>
<th data-column-id="position">Position</th>
<th data-column-id="department">Department</th>
<th data-column-id="vacancy">Vacancy</th>
<th data-column-id="postingdate">Date</th>
<th data-column-id="status">Status</th>
<th data-column-id="qualification" clas="hidden-lg"></th>
<th data-column-id="experience" class="hidden-lg"></th>
<th data-column-id="criteria1" class="hidden-lg"></th>
<th data-column-id="criteria2" class="hidden-lg"></th>
<th data-column-id="criteria3" class="hidden-lg"></th>
<th data-column-id="jd1" ></th>
<th data-column-id="jd2" ></th>
<th data-column-id="jd3" ></th>
<th data-column-id="jd4" ></th>
<th data-column-id="jd5" ></th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
</table>
</div>
i want to hide this
<th data-column-id="qualification" data-class="hidden"></th>
<th data-column-id="experience" data-class="hidden"></th>
<th data-column-id="criteria1" data-class="hidden"></th>
<th data-column-id="criteria2" data-class='hidden'></th>
<th data-column-id="criteria3" data-class='hidden'></th>
<th data-column-id="jd1" ></th>
<th data-column-id="jd2" ></th>
<th data-column-id="jd3" ></th>
<th data-column-id="jd4" ></th>
<th data-column-id="jd5" ></th>
but..if i hide those value..i cant access them at
grid.find(".command-edit").on("click", function(e)
{
//alert("You pressed edit on row: " + $(this).data("row-id"));
var ele =$(this).parent();
var g_id = $(this).parent().siblings(':first').html();
var g_name = $(this).parent().siblings(':nth-of-type(7)').html();
console.log(g_id);
console.log(g_name);
//console.log(grid.data());//
$('#edit_model').modal('show');
if($(this).data("row-id") >0) {
// collect the data
// $('#edit_id').val(ele.siblings(':first').html()); // in case we're changing the key
$('#edit_position').val(ele.siblings(':nth-of-type(2)').html());
$('#edit_department').val(ele.siblings(':nth-of-type(3)').html());
$('#edit_vacancy').val(ele.siblings(':nth-of-type(4)').html());
$('#edit_qualification').val(ele.siblings(':nth-of-type(7)').html());
$('#edit_experience').val(ele.siblings(':nth-of-type(8)').html());
$('#edit_postingdate').val(ele.siblings(':nth-of-type(5)').html());
$('#edit_status').val(ele.siblings(':nth-of-type(6)').html());
// $('#edit_description').val(ele.siblings(':nth-of-type(9)').html());
} else {
alert('Now row selected! First select row, then click edit button');
}
})
i have tried solution at Bootstrap-Table: How to hide a column without deleting it from the DOM?
but it doesnt seem to hide the column at all
If you are using bootstrap 4+ just add the class .d-none to your columns,
which will set display: none on them.
If you are using bootstrap 3+ it should be .hidden-* where as * is
xs
sm
md
lg
for the different screen sizes.
Maybe .hidden works as well without the size selector...

sending mail to multiple recipients (continue)

I just want to send multiple email to the recipients using mail() when i update the order status to notify the customers. (Im using my own email as testing, and each of the order from 1 to 10 is my email.)
So im suppose to receieved more than one email to myself..
But when i did it, i receieved only one email and inside that email at the "to" section, its display my email 10 times !! (to ahmadxxx#hotmail.com, ahmadxxx#hotmail.com, ahmadxxx#hotmail.com ... )
This is my form.
<form action="results-action" method="post" enctype="multipart/form-data">
<fieldset>
<table id ="table_id" class="display">
<thead>
<tr><td><h2>Pending Order</h2></td></tr>
<tr>
<th scope="col">Order ID</th>
<th scope="col">Order Number</th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Payment Method</th>
<th scope="col">Order Date</th>
<th scope="col">Product Name</th>
<th scope="col">Produt Quantity</th>
<th scope="col">Price</th>
<th scope="col">Order status</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" value='<?=$row['virtuemart_order_id']?>' name="orderid" id="virtuemart_order_id"></td>
<td><?=$row['order_number']?></td>
<td><?=$row['first_name']?></td>
<td><?=$row['address_1']?></td>
<td><?=$row['payment_element']?></td>
<td><?=$row['created_on']?></td>
<td><?=$row['order_item_name']?></td>
<td><?=$row['product_quantity']?></td>
<td><?=$row['product_final_price'] ?></td>
<td><select name='change[<?=$row['virtuemart_order_id']?>]'>
<option value='C'> Confirmed</option>
<option value='X'> Cancelled</option></select></td>
</tr>
<?php
}
?>
</tbody>
</table>
</fieldset>
<fieldset>
<table>
<tr>
<td><input type="submit" value="Update status" name="update status"> </td>
</tr>
</table>
</fieldset>
</form>
This is my codes.
<?php
//filtering confirmed orders
function confirmed($v){return($v =='C');}
// pick the rows in your form table which have been set as confirmed, and use the keys
$id = implode(',', array_keys(array_filter($_POST['change'],'confirmed')));
// build SQL statement mail
$query3 = "SELECT * from ruj3d_virtuemart_order_userinfos where virtuemart_order_id IN (".$id.")";
// execute SQL statement
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
while($row3 = mysqli_fetch_array($result3)){
$addresses[]=$row3['email'];
}
$to = implode(", ",$addresses);
$subject = "Order confirmed by Home and decor";
// message
$message = '
<html>
<body>
<table width="500" height="215" border="0">
<tr>
<th width="238" height="211" scope="col"><h1 align="left">Order # 1234</h1></p></th>
<th width="10" scope="col"></th>
<th width="243" scope="col"><p><img src="file:///D|/Programs/xampp/htdocs/images/sitelogo.PNG" width="224" height="68" align="right"></p></th>
</tr>
</table>
<table width="500" height="215" border="0">
<tr>
<th width="181" height="211" scope="col"><p align="left">Ship To:</p>
<p align="left">Customer name</p>
<p align="left">Blk 123</p>
<p align="left">Singapore, 123123</p></th>
<th width="80" scope="col"></th>
<th width="40" scope="col"></th>
<th width="181" scope="col"><p align="left"></p>
<p align="right">Bill To:</p>
<p align="right">Customer name</p>
<p align="right">Blk 123</p>
<p align="right">Singapore, 123123</p>
</th>
</tr>
</table>
<table width="500" height="94" border="0">
<tr>
<th height="43" scope="col"><div align="left">Order Date:</div></th>
<th scope="col"> </th>
<th scope="col"> </th>
<th scope="col"><div align="right">Shipping Method:</div></th>
</tr>
<tr>
<th width="126" height="43" scope="col"><div align="left">1/11/13</div></th>
<th width="433" scope="col"> </th>
<th width="103" scope="col"> </th>
<th width="156" scope="col"><div align="right">BEAST!</div></th>
</tr>
</table>
<table width="500" height="88" border="1">
<tr>
<th width="48" scope="col">Item</th>
<th width="264" scope="col">Product Name</th>
<th width="68" scope="col">Quantity</th>
<th width="92" scope="col">Price</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<hr>
<table width="500" height="227" border="0">
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Subtotal:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Tax:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Shipping:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Discount:</th>
<th scope="col"> </th>
</tr>
<tr>
<th width="40" height="43" scope="col"> </th>
<th width="278" scope="col"> </th>
<th width="68" scope="col">Grand Total:</th>
<th width="96" scope="col"> </th>
</tr>
</table>
<p align="right"> </p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
?>
You need to move the code that composes and sends the mail inside the
while ($row3 = mysqli_fetch_array($result3)) {
...
}
loop, instead of making an array of all the addresses.

sending mail message php

i just want to send the order content fetching the result in my database.
But when i echo it, it displays it on my php page. i dont want it.
I want the content to only appear in the email when the user receive it.
This is my code.
while($row3 = mysqli_fetch_array($result3)){
$addresses=$row3['email'];
$to = $addresses;
$subject = "Order confirmed by Home and decor";
// message
$message = '
<html>
<body>
<table width="500" height="215" border="0">
<tr>
<th width="238" height="211" scope="col"><h1 align="left">Order # 1234</h1></p></th>
<th width="10" scope="col"></th>
<th width="243" scope="col"><p><img src="file:///D|/Programs/xampp/htdocs/images/sitelogo.PNG" width="224" height="68" align="right"></p></th>
</tr>
</table>
<table width="500" height="215" border="0">
<tr>
<th width="181" height="211" scope="col"><p align="left">Ship To:</p>
<p align="left"><?=$row3['first_name']?></p>
<p align="left"><?=$row3['address_1']?></p>
<p align="left"><?=$row3['city']?></p></th>
<th width="80" scope="col"></th>
<th width="40" scope="col"></th>
<th width="181" scope="col"><p align="left"></p>
<p align="right">Bill To:</p>
<p align="right"><?=$row3['first_name']?></p>
<p align="right"><?=$row3['address_1']?></p>
<p align="right"><?=$row3['city']?></p>
</th>
</tr>
</table>
<table width="500" height="94" border="0">
<tr>
<th height="43" scope="col"><div align="left">Order Date:</div></th>
<th scope="col"> </th>
<th scope="col"> </th>
<th scope="col"><div align="right">Shipping Method:</div></th>
</tr>
<tr>
<th width="126" height="43" scope="col"><div align="left">1/11/13</div></th>
<th width="433" scope="col"> </th>
<th width="103" scope="col"> </th>
<th width="156" scope="col"><div align="right">BEAST!</div></th>
</tr>
</table>
<table width="500" height="88" border="1">
<tr>
<th width="48" scope="col">Item</th>
<th width="264" scope="col">Product Name</th>
<th width="68" scope="col">Quantity</th>
<th width="92" scope="col">Price</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<hr>
<table width="500" height="227" border="0">
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Subtotal:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Tax:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Shipping:</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="43" scope="col"> </th>
<th scope="col"> </th>
<th scope="col">Discount:</th>
<th scope="col"> </th>
</tr>
<tr>
<th width="40" height="43" scope="col"> </th>
<th width="278" scope="col"> </th>
<th width="68" scope="col">Grand Total:</th>
<th width="96" scope="col"> </th>
</tr>
</table>
<p align="right"> </p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Order reminder <lol#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
}
Echo is when you want to call something out right. I dont want it to echo, i just want to make the content appear in the email without echoing it.
Don't echo your variables, concatenate them into the string. i.e.
$message = "Some text ".$foo." some more text';
Not:
$message = "Some text <?=$foo ?> some more text';
Check out this PHP Documentation for Turn on output buffering.
http://php.net/manual/en/function.ob-start.php
Thanks
what are the sally wrong shorttag doing right in the middle of your message content.
<?= ?>
see this post for more information about shorttags
I'd just replace all those things from
<?php
$message '...
<p align="left"><?=$row3['first_name']?></p>
to
<?php
$message '...
<p align="left">'.$row3['first_name'].'</p>
You could use Heredoc syntax for this:
$message =<<<EOM
<html>
<body>
...
<table width="500" height="215" border="0">
<tr>
<th width="181" height="211" scope="col"><p align="left">Ship To:</p>
<p align="left">{$row3['first_name']}</p>
<p align="left">{$row3['address_1']}</p>
<p align="left">{$row3['city']}</p></th>
...
EOM;
It's recommended to apply htmlspecialchars() on $row3 first though:
$row3 = array_map('htmlspecialchars', $row3);
This assumes you will not use $row3 later in your code

Categories