代码之家  ›  专栏  ›  技术社区  ›  Chase Price

如何将POST表单数据放入电子邮件

  •  0
  • Chase Price  · 技术社区  · 7 年前

    我正在制作一张表格,让我的客户在订购产品时填写。
    我正在努力做到这一点,当他们点击提交它的电子邮件数据到我的电子邮件和它抄送的他们。电子邮件中会有样式。我不知道如何让它把数据放到电子邮件中。我目前正在使用PHPMailer。

    <?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('No-Reply@LDSVacuum.com');
    $mail->Subject = 'Request';
    $mail->AddAddress('Chase.Price@LDSVacuum.com');
    $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 Info@LDSVacuum.com . 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"> 
    	<p>
    		<label for='First_Name' class="FG3" width="157">
    			<span class="red">
    				*
    			</span> 
    			First Name:
    		</label>
    			<br />
    		<input type="text" name="First_Name" id="First_Name" class="FG2" size="50" placeholder="John">
    			<br />
    		<label for='Last_Name' class="FG3">
    			<span class="red">
    				*
    			</span> 
    			Last Name:
    		</label>
    			<br />
    		<input type="text" name="Last_Name" class="FG2" size="50" placeholder="Johnson">
    			<br />
    		<label for='Email' class="FG3">
    			<span class="red">
    				*
    			</span> 
    			Your Email Address:
    		</label>
    			<br />
    		<input type="text" name="Email" id="Email" class="FG2" size="50" placeholder="John_Johnson@company.com">
    			<br />
    		<label for='Company' class="FG3">
    			<span class="red">
    				*
    			</span> 
    			Company Name:
    		</label>
    			<br />
    		<input type="text" name="Company" class="FG2" size="50" placeholder="Company Inc.">
    			<br />
    	</p>
      </form>
      <br />
      <input type="Submit" value="Submit">
    1 回复  |  直到 7 年前
        1
  •  0
  •   Quentin    7 年前

    你是:

    1. 创建HTML字符串
    2. 从HTML字符串创建DOM
    3. 通过设置值修改DOM
    4. 通过电子邮件发送HTML的原始字符串并忽略生成的DOM

    $modified_html = $dochtml->saveHTML() )然后发送它,而不是原始字符串。