2017-10-16 79 views
0

我正在爲我的客戶在訂購產品時填寫表格。
我想讓它如此,當他們點擊提交時,它將數據發送給我的電子郵件,它的cc是他們。該電子郵件將具有樣式。我無法弄清楚如何讓它把數據放入電子郵件。我目前使用PHPMailer。
這裏是php文件如何將POST表單數據寫入電子郵件

<?php 

$FirstName = $_POST['First_Name']; 
$LastName = $_POST['Last_Name']; 
$Email = $_POST['Email']; 
$Company = $_POST['Company']; 


$dochtml = new DOMDocument(); 
require_once('PHPMailer/PHPMailerAutoload.php'); 
$mail = new PHPMailer(); 
$mail->isSMTP(); 
$mail->SetFrom('[email protected]'); 
$mail->Subject = 'Request'; 
$mail->AddAddress('[email protected]'); 
$mail->AddCC($Email); 
$strhtml = ' 
<div align="center"> 
<font face="arial" color="#336699" size="6"> 
    Request 
</font> 
</div> 
<div> 
<font face="arial" color="#336699" size="5"> 
    Customer Information 
</font> 
<p> 
    <label for="fname"> 
     <font face="arial" color="#336699" size="4"> 
      First Name: 
     </font> 
    </label> 
    <br /> 
    <input type="text" name="fname" id="fname" size="50"> 
</p> 
<p> 
    <label for="lname"> 
     <font face="arial" color="#336699" size="4"> 
      Last Name: 
     </font> 
    </label> 
    <br /> 
    <input type="text" name="lname" id="lname" size="50"> 
</p> 
<p> 
    <label for="email"> 
     <font face="arial" color="#336699" size="4"> 
      Email Address: 
     </font> 
    </label> 
    <br /> 
    <input type="text" name="email" id="email" size="50"> 
</p> 
<p> 
    <label for="company"> 
     <font face="arial" color="#336699" size="4"> 
      Company Name: 
     </font> 
    </label> 
    <br /> 
     <input type="text" name="company" id="company"size="50"> 
</p> 
</div> 
'; 

$dochtml->loadHTML($strhtml); 
$fname = $dochtml->getElementById('fname'); 
$fname->value=$FirstName; 
$lname = $dochtml->getElementById('lname'); 
$lname->value=$LastName; 
$email = $dochtml->getElementById('email'); 
$email->value=$Email; 
$company = $dochtml->getElementById('company'); 
$company->value=$FirstName; 

$mail->Body = $strhtml; 

$mail->Send(); 

if(!$mail->Send()) { 
echo 'Unknown Error has Occured. Please try again Later.'; 
echo 'Mailer error: ' . $mail->ErrorInfo; 
}else { 
    echo 'Thank You, $FirstName . We have emailed your request to [email protected] . Your email $Email has been cc to the email.'; 
} 

?> 

這裏是形式

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form method="POST" name="contactform" autocomplete="off" id="nipplerequest" action="http://localhost/emailform.php"> 
 
\t <p> 
 
\t \t <label for='First_Name' class="FG3" width="157"> 
 
\t \t \t <span class="red"> 
 
\t \t \t \t * 
 
\t \t \t </span> 
 
\t \t \t First Name: 
 
\t \t </label> 
 
\t \t \t <br /> 
 
\t \t <input type="text" name="First_Name" id="First_Name" class="FG2" size="50" placeholder="John"> 
 
\t \t \t <br /> 
 
\t \t <label for='Last_Name' class="FG3"> 
 
\t \t \t <span class="red"> 
 
\t \t \t \t * 
 
\t \t \t </span> 
 
\t \t \t Last Name: 
 
\t \t </label> 
 
\t \t \t <br /> 
 
\t \t <input type="text" name="Last_Name" class="FG2" size="50" placeholder="Johnson"> 
 
\t \t \t <br /> 
 
\t \t <label for='Email' class="FG3"> 
 
\t \t \t <span class="red"> 
 
\t \t \t \t * 
 
\t \t \t </span> 
 
\t \t \t Your Email Address: 
 
\t \t </label> 
 
\t \t \t <br /> 
 
\t \t <input type="text" name="Email" id="Email" class="FG2" size="50" placeholder="[email protected]"> 
 
\t \t \t <br /> 
 
\t \t <label for='Company' class="FG3"> 
 
\t \t \t <span class="red"> 
 
\t \t \t \t * 
 
\t \t \t </span> 
 
\t \t \t Company Name: 
 
\t \t </label> 
 
\t \t \t <br /> 
 
\t \t <input type="text" name="Company" class="FG2" size="50" placeholder="Company Inc."> 
 
\t \t \t <br /> 
 
\t </p> 
 
    </form> 
 
    <br /> 
 
    <input type="Submit" value="Submit">

回答

0

您的位置:

  1. 創建HTML
  2. 的字符串
  3. 通過設定值
  4. 通過電子郵件發送HTML的原始字符串,而忽略你產生

您需要將DOM轉換回的HTML DOM(創建從HTML

  • 修改該DOM的該字符串DOM $modified_html = $dochtml->saveHTML())併發送,而不是您的原始字符串。

  • +0

    我得到這個錯誤:注意:未定義的屬性:DOMDocument :: $ saveHTML –

    +2

    'saveHTML()'是一種方法,而不是屬性。如果你稍微嘗試閱讀文檔,這可能會有所幫助。 – Synchro

    相關問題