繁体   English   中英

如何通过电子邮件发送电子邮件并格式化处理过的页面?

[英]how to email and format a processed page with php?

我有一个“打印”按钮,也没有一个“电子邮件”按钮。 我想通过电子邮件在订单上单击“单击添加”(输入类型=“ image”)后显示的页面内容。 基本上,这只是一个订购表,具有多个“数字”输入类型,我想对其进行格式化并通过电子邮件发送这些数量。 我需要先将整个页面转换为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 .  "&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: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>

正如我在评论中提到的那样,您可以使用输出缓冲来捕获通过电子邮件发送的内容。 无需为此创建其他PDF。

您只需将分配的变量带到ob_get_contents()并将其用作邮件正文。

这是一个非常基本的示例(从此页面中拉出),但是您需要通过简单地将需要捕获的内容放在ob_start();之间进行实验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

脚注:

您在shop home</a></h5有一个未关闭的<h5>标签shop home</a></h5 <<<。

我注意到您正在使用图像。 您可能必须使用完整的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的表单教程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM