我有一个“打印”按钮,我也不是一个“电子邮件”按钮。我想在订单上单击“单击添加”(输入类型=“图像”)后显示的页面内容通过电子邮件发送。它基本上只是一个包含多个“数字”输入类型的订单,我想格式化并通过电子邮件发送这些数量。我需要先将整个页面转换为PDF吗?我将有多种形式(服装款式)将被处理。谢谢!
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 . " - X-Small" . "</li>";
echo "<li>" . $sm . " - Small" . "</li>";
echo "<li>" . $md . " - Medium" . "</li>";
echo "<li>" . $lg . " - Large" . "</li>";
echo "<li>" . $xl . " - X-Large" . "</li>";
echo "<li>" . $xxl . " - 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:example@cox.net?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>
答案 0 :(得分:1)
正如我在评论中提到的,您可以使用output buffering来捕获通过电子邮件发送的内容。没有必要为此创建额外的PDF。
您只需将指定的变量带到ob_get_contents()
并将其用作邮件正文。
以下是一个非常基本的示例(摘自this page),但您只需在ob_start();
和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;
?>
$getContent
变量将用作邮件正文参数。
使用PHP mail()
函数的示例:
mail($to, $subject, $getContent, $headers);
参考:
请记住以HTML格式发送,因为您在这里使用HTML。
您也可以使用phpmailer https://github.com/PHPMailer/PHPMailer
<强> Foonotes:强>
<h5>
中有一个未公开的shop home</a></h5
标记&lt;&lt;&lt;就在那里。
我注意到你正在使用图像。您可能必须使用完整的HTTP调用。
即:
<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>
要发送从表单中获取的邮件,您需要使用PHP,而不是您在此处使用的<a href="mailto:example@cox.net?subject=Summer...
链接。
看一下PHP的表格教程