2016-05-29 123 views
0

我有一個「打印」按鈕,我也不想「電子郵件」按鈕。我想通過電子郵件發送在訂單上點擊「點擊添加」(輸入類型=「圖片」)後出現的頁面內容。它基本上只是一個具有多個「數字」輸入類型的訂單,我想對這些數量進行格式化和發送電子郵件。我是否需要首先將整個頁面轉換爲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:[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> 
+1

你可以使用輸出緩衝和得到什麼的在屏幕上生成的電子郵件 - http://php.net/manual/en/book。 outcontrol.php - http://php.net/manual/en/function.ob-start.php - 這樣你就不需要生成pdf –

+0

@ Fred-ii-,謝謝你的回覆!我做了一些關於輸出緩衝的瞭解,並且認爲它是代碼執行的暫停(緩衝)或將頁面的全部內容製作爲單個變量的一種方式。後者是我所希望的,但是我怎麼把它傳遞給電子郵件呢?我是否僅爲電子郵件腳本創建單獨的頁面並將該變量添加到某處? – Bigfootbud

+1

不客氣。是;您將使用的變量將從輸出緩衝區中分配,並使用該分配的變量作爲郵件消息主體。你只需要捕捉你想要郵寄的東西。但是,您需要將其作爲HTML發送。如果您打算使用該函數,請參閱「mail()」手冊http://php.net/manual/en/function.mail.php或phpmailer https://github.com/PHPMailer/PHPMailer –

回答

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:

你有shop home</a></h5 < < <右邊有一個未關閉<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:[email protected]?subject=Summer...鏈接。

看一看PHP的形式教程

+0

我有很多不同的經驗,在不同的電子郵件客戶端糟糕地呈現html內容佈局。除了最微不足道的內聯css之外的任何東西很少看起來完全正確。我發現的最好的方法是建立一個pdf並附加它,所以FPDF的榮譽。更好的收據,我預先在Acrobat中生成表格,生成FDF,然後用PDFTK填充和壓平。這是另一個前沿的學習曲線,但從長遠來看,你會獲得更多。 –

+0

@JeffPuckettII我理解傑夫。那麼,我希望我所建議的將會有所幫助。這是我現在能提供的最好的。我已經使用了上面的方法很多次,並且已經成功地發送了HTML格式的表格。 TBH Jeff,我從來沒有發過PDF文件。 –