0

I have a "print" button, I wan't an "email" button also. I want to email the content of the page that appears after I click "Click To Add"(input type="image") on the order form. It's basically just an order form with multiple "number" input types that I want to format and email those quantities. Do i need to convert the whole page to PDF first? I will have multiple forms(styles of apparel) that will be processed. Thanks!

Link to test page: http://taketwodesigns.com/monkeypod/order/


    <!---------------------- 1ST STYLE BELOW ----------------------------->
 <form action="processors/process_xs-xxl.php" method="post" name="order_form1" class="margins">

<div class="item_image_container">
<span class="item_name">Item ~ MLTA107-101TEV</span>
<a href="images/styles/large/mlta107_101tev_big.jpg" target="_blank"><img class="item_image" src="images/styles/thumbs/mlta107_101tev_thumb.jpg" /></a>
<span class="click_full_image">Click image for full size</span>
</div><!-- ITEM_IMAGE div CLOSE -->

<table border="1" cellspacing="1">
<tr class="gridaddrows">
<td colspan=8 class="radius">
<div class="formtext"><b>You must click the "Add to Cart" button to place items in cart.</b></div>
</td>
</tr>
<tr class="gridrows">
<td class="gridtitle">Add</td>
<td class="gridtitle">XS</td>
<td class="gridtitle">S</td>
<td class="gridtitle">M</td>
<td class="gridtitle">L</td>
<td class="gridtitle"></td>
<td class="gridtitle"></td>
</tr>

<td class="add_to_cart_btn">
<input type="image" src="../order/images/clicktoadd83pxfast.gif"  name="mlta107_101tev" alt="Add to Cart" /></td>

<td><span class="price">$11.25</span><br>
<input type="number" name="xs" placeholder="Qty" min="0" max="288" autocomplete="off"></td>

<td><span class="price">$11.25</span><br>
<input type="number" name="sm" placeholder="Qty" min="0" max="288" autocomplete="off"></td>

<td><span class="price">$11.25</span><br>
<input type="number" name="md" placeholder="Qty" min="0" max="288" autocomplete="off"></td>

<td><span class="price">$11.25</span><br>
<input type="number" name="lg" placeholder="Qty" min="0" max="288"  autocomplete="off"></td>

<td><!-- span class="price">$11.25</span><br -->
<input type="number" name="xl" placeholder="Qty" min="0" max="288" style="visibility: hidden;" autocomplete="off"></td>

<td><!-- span class="price">$11.25</span><br -->
<input type="number" name="xxl" placeholder="Qty" min="0" max="288" style="visibility: hidden;" autocomplete="off"></td>

</table>
</form>



<!DOCTYPE html>               <!-- process_xs-xxl.php -->
<html>
<head>
<title>MPK MLTA107-101TEV</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<meta content="width=device-width, initial-scale=1, user-scalable=yes" name="viewport" />   
<link rel="stylesheet" href="../css/cart.css" type="text/css" />
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/print.css" media="print">
</head>
<body>

<div id="divToPrint">

<h1>MONKEYPOD KITCHEN ONLINE ORDERING</h1>

<?php

date_default_timezone_set('Pacific/Honolulu');
$date = date("l, F jS Y g:i:s A");

$xs  = $_POST['xs'];
$sm  = $_POST['sm'];
$md  = $_POST['md'];
$lg  = $_POST['lg'];
$xl  = $_POST['xl'];
$xxl = $_POST['xxl'];

    if($_POST['xs'] ||
       $_POST['sm'] ||
       $_POST['md'] ||
       $_POST['lg'] || 
       $_POST['xl'] ||
       $_POST['xxl'] ){ 

$xs  = ltrim($xs, '0');
$sm  = ltrim($sm, '0');
$md  = ltrim($md, '0');
$lg  = ltrim($lg, '0');
$xl  = ltrim($xl, '0');
$xxl = ltrim($xxl, '0');

    echo '<h6 class="great">Thank you for your order!</h6>';

    echo "<hr>";

    echo "<h5>Your order date is:<br>$date<br>Hawaiian Time! Mahalo!</h5>";

    echo "<ul><h3>Ordered Items Below</h3><h4>Item# MLTA107-101TEV</h4>";

    echo "<li>" . $xs .  "&nbsp; -&nbsp; X-Small" . "</li>";
    echo "<li>" . $sm . "&nbsp; -&nbsp; Small" . "</li>";
    echo "<li>" . $md . "&nbsp; -&nbsp; Medium" . "</li>";
    echo "<li>" . $lg . "&nbsp; -&nbsp; Large" . "</li>";
    echo "<li>" . $xl . "&nbsp; -&nbsp; X-Large" . "</li>";
    echo "<li>" . $xxl . "&nbsp; -&nbsp; XX-Large" . "</li>";

    echo "</ul>";

    }else{  
            echo '<h2>Oppsiedasies! It looks like you didn\'t order anything!<br>Back to <a href=".">shop home</a></h2>';
        }               
?>

<?php
    echo '<div class="print_button_div"><input type="button" value="Print Order" onclick="PrintDiv();" /></div>';   
?>

<?php

echo '<a href="mailto:[email protected]?subject=Summer%20Party&body=$xs%20You%20are%20invited%20to%20a%20big%20summer%20party!" target="_top">Send mail!</a>';

?>

<h5>Test for echo....<br>Back to <a href=".">shop home</a></h5>

</div><!-- TO PRINT div CLOSE -->

<script type="text/javascript">     
    function PrintDiv() {    
       var divToPrint = document.getElementById('divToPrint');
       var popupWin = window.open('', '_blank', 'width=800,height=800,background-color=red');
           popupWin.document.open();
           popupWin.document.write('<html><head><style></style></head><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
           popupWin.document.close();
    }
</script>

</body>
</html>
5
  • 1
    you could use output buffering and get what's generated on screen emailed - php.net/manual/en/book.outcontrol.php - php.net/manual/en/function.ob-start.php - that way you wouldn't need to generate a pdf May 29, 2016 at 2:51
  • @Fred-ii-, thanks for responding! I did some reading about Output Buffering and came away with it being a pausing(buffering) of code execution or a way to make the entire contents of a page into a single variable. The latter is what I would hope for, but how then do I pass it to an email? Do I create a separate page just for the email scripting and add the variable in there somewhere?
    – Bigfootbud
    May 29, 2016 at 8:00
  • 1
    You're welcome. Yes; the variable you'd use would be assigned from the output buffering and using that assigned variable as the mailed message body. You just need to capture what you would like to have mailed. However, you would need to send it as HTML. See the manual on mail() if you intend on using that function php.net/manual/en/function.mail.php or phpmailer github.com/PHPMailer/PHPMailer May 29, 2016 at 13:19
  • Addendum to above; if you intend on using external stylesheets for styling, that may not work as many email clients will ignore them. You will need to use inline CSS for that. May 29, 2016 at 13:24
  • Btw, you have an unclosed <h5> tag shop home</a></h5 <<< right there ;-) May 29, 2016 at 13:34

1 Answer 1

0

As I mentioned in comments, you can use output buffering to capture content sent by email. There's no need to create an additional PDF for this.

You simply take the assigned variable to ob_get_contents() and use that as the mail body.

Here is a very basic example (pulled from this page), but you will need to experiment with this by simply placing what you need to capture between ob_start(); and ob_end_clean();.

<?php

  // Start buffering
  ob_start();

  // Output stuff (probably not this simple, might be custom CMS functions...
  echo 'Print to the screen!!!';
  echo "<br>Print this to screen also.";

  // Get value of buffering so far
  $getContent = ob_get_contents();

  // Stop buffering
  ob_end_clean();

  // Do stuff to $getContent as needed

  // Use it
  echo 'Now: ' . $getContent;

?>

The $getContent variable would be used as the mail body parameter.

Example using PHP's mail() function:

mail($to, $subject, $getContent, $headers);

Reference:

And remember to send as HTML, since you are using HTML here.

You can also use phpmailer https://github.com/PHPMailer/PHPMailer

Foonotes:

You have an unclosed <h5> tag in shop home</a></h5 <<< right there.

I noticed you are using images. You may have to use a full HTTP call for those.

I.e.:

<a href="http://www.example.com/images/styles/large/mlta107_101tev_big.jpg" target="_blank"><img class="item_image" src="http://www.example.com/images/styles/thumbs/mlta107_101tev_thumb.jpg" /></a>

To send mail taken from a form, you would need to use PHP for that, rather than the <a href="mailto:[email protected]?subject=Summer... link you're using here.

Have a look at PHP's forms tutorial

2
  • I've had a lot of bad experiences with wide differences in the way different email clients poorly render html content layout. Anything beyond the most trivial inline css rarely looks exactly right. The best way I've discovered is to build a pdf and attach it, so kudos for FPDF. Even better for receipts, in advance I build forms in Acrobat, generate FDFs, then fill and flatten with PDFTK. It's another upfront learning curve, but you'll get much more in the long run. May 29, 2016 at 14:11
  • @JeffPuckettII I understand Jeff. Well, I hope that what I've suggested will be of help. That's the best I can offer at this time. I've used the above method quite a few times and have been successful for me, and sending HTML formatted tables. TBH Jeff, I never did send out as PDF documents. May 29, 2016 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.