【问题标题】:Converting a .asp form that sends email to WordPress转换向 WordPress 发送电子邮件的 .asp 表单
【发布时间】:2020-07-07 05:46:18
【问题描述】:

我对 WordPress 和 Web 开发还很陌生。我一直在为与我有业务往来的人将旧网站转换为 WordPress。我几乎完成了所有工作,但我无法让他的联系表正常工作。我已经为该页面创建了一个自定义模板,但不确定如何在电子邮件发送到工作时获取该页面。我的模板代码是这样的

<?php
/*Template Name: Contact*/
?>
<?php
get_header();
?>




<?php $nav = get_field ('navigation_links'); ?>
<body bgcolor="#ffffff" onload="MM_preloadImages('<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s4.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s3.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s4.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s3.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s4.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s3.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s4.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s3.png');">

<div class = "container" style = "background-image:url(<?php bloginfo('template_directory')?>/images/Generic_Background.jpg);">
<div id="header" style="position:relative;">
  <div id="FWTableContainer1270816879">
    <table style="display: inline-table;" border="0" cellpadding="0" cellspacing="0" width="960">
      <!-- fwtable fwsrc="masthead.png" fwpage="Page 1" fwbase="masthead.png" fwstyle="Dreamweaver" fwdocid = "1270816879" fwnested="0" -->
      <tr>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="179" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="55" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="179" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="89" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="179" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="68" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="199" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="12" height="1" border="0" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
      </tr>
      <tr>
        <td colspan="8"><img name="masthead_r1_c1_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r1_c1_s1.png" width="960" height="193" border="0" id="masthead_r1_c1_s1" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="1" height="193" border="0" alt="" /></td>
      </tr>
      <tr>
        <td><a href="<?php echo $nav['home_link'];?>" onmouseout="MM_nbGroup('out');" onmouseover="MM_nbGroup('over','masthead_r2_c1_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s4.png',1);" onclick="MM_nbGroup('down','navbar1','masthead_r2_c1_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s3.png',1);"><img name="masthead_r2_c1_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c1_s1.png" width="179" height="43" border="0" id="masthead_r2_c1_s1" alt="" /></a></td>
        <td><img name="masthead_r2_c2_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c2_s1.png" width="55" height="43" border="0" id="masthead_r2_c2_s1" alt="" /></td>
        <td><a href="javascript:;" onmouseout="MM_nbGroup('out');MM_menuStartTimeout(1000);" onmouseover="MM_menuShowMenu('MMMenuContainer1120175513_0', 'MMMenu1120175513_0',0,43,'masthead_r2_c3_s1');MM_nbGroup('over','masthead_r2_c3_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s4.png',1);" onclick="MM_nbGroup('down','navbar1','masthead_r2_c3_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s3.png',1);"><img name="masthead_r2_c3_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c3_s1.png" width="179" height="43" border="0" id="masthead_r2_c3_s1" alt="" /></a></td>
        <td><img name="masthead_r2_c4_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c4_s1.png" width="89" height="43" border="0" id="masthead_r2_c4_s1" alt="" /></td>
        <td><a href="<?php echo $nav['link_dealers'];?>" onmouseout="MM_nbGroup('out');" onmouseover="MM_nbGroup('over','masthead_r2_c5_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s4.png',1);" onclick="MM_nbGroup('down','navbar1','masthead_r2_c5_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s3.png',1);"><img name="masthead_r2_c5_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c5_s1.png" width="179" height="43" border="0" id="masthead_r2_c5_s1" alt="" /></a></td>
        <td><img name="masthead_r2_c6_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c6_s1.png" width="68" height="43" border="0" id="masthead_r2_c6_s1" alt="" /></td>
        <td><a href="<?php echo $nav['link_contact'];?>" onmouseout="MM_nbGroup('out');" onmouseover="MM_nbGroup('over','masthead_r2_c7_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s2.png','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s4.png',1);" onclick="MM_nbGroup('down','navbar1','masthead_r2_c7_s1','<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s3.png',1);"><img name="masthead_r2_c7_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c7_s1.png" width="199" height="43" border="0" id="masthead_r2_c7_s1" alt="" /></a></td>
        <td><img name="masthead_r2_c8_s1" src="<?php bloginfo('template_directory')?>/menu_images/masthead_r2_c8_s1.png" width="12" height="43" border="0" id="masthead_r2_c8_s1" alt="" /></td>
        <td><img src="<?php bloginfo('template_directory')?>/menu_images/spacer.gif" width="1" height="43" border="0" alt="" /></td>
      </tr>
    </table>
    <div id="MMMenuContainer1120175513_0">
      <div id="MMMenu1120175513_0" onmouseout="MM_menuStartTimeout(1000);" onmouseover="MM_menuResetTimeout();"> <a href="<?php echo $nav['link_pistols'];?>" id="MMMenu1120175513_0_Item_0" class="MMMIFVStyleMMMenu1120175513_0" onmouseover="MM_menuOverMenuItem('MMMenu1120175513_0');"> Pistols&nbsp;&amp;&nbsp;Knives </a> <a href="<?php echo $nav['link_rifles'];?>" id="MMMenu1120175513_0_Item_1" class="MMMIVStyleMMMenu1120175513_0" onmouseover="MM_menuOverMenuItem('MMMenu1120175513_0');"> Rifles&nbsp;&amp;&nbsp;Shotguns </a> <a href="<?php echo $nav['link_collectibles'];?>" id="MMMenu1120175513_0_Item_2" class="MMMIVStyleMMMenu1120175513_0" onmouseover="MM_menuOverMenuItem('MMMenu1120175513_0');"> Collectibles&nbsp;&amp;&nbsp;Antiques </a> </div>
    </div>
  </div>
</div>

<div class="content"  style="position:relative;">
  <!-- InstanceBeginEditable name="maincontent" --><div id="centertable"><center><table width="70%" border="0" cellpadding="2" cellspacing="0"  style="background-color:#fcb076;">
   <tr>
     <td align="center"><h2 style="margin-top:4px;">Contact Information</h2>        <h5>Phone: 574.295.6440<br />
       Monday – Friday 9:00 am – 5:00 pm        Eastern Standard Time</h5>
       <h5>Saturdays 9:00 am - noon<br />
         Fax: 574.522.1600 (Anytime)</h5></td>
     
     </tr>
   <tr>
     <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
       <tr>
         <td align="center"><h5>Mailing Address:<br />
           22382 State Road 120 Elkhart, IN 46516</h5></td>
         <td align="center"><h5>Physical Address:<br />
           22382 State Road 120 Elkhart, IN 46516</h5></td>
         </tr>
       </table></td>
     
     </tr>
   <tr>
     <td align="center"><h5>E-mail - <a href="mailto:paul.stybert@gmail.com">paul.stybert@gmail.com</a></h5></td>
     
     </tr>
   <tr>
     <td><h5>If you have questions, you can reach us by phone, fax, regular mail, or use the email form below. This form will be sent to a customer service representative, who will be in contact with you soon. Thank you for your interest in Doug's Guns.</h5></td>
     
     </tr>
   <tr style="background-color:#005d90;color:#fff;">
     <td align="center" style="border:1px solid #000;"><h3>Online Information Request Form</h3></td>
     </tr>
   <tr >
     <td align="center" style="border:1px solid #000;background-color:#d3a06f;"><form action="<?php bloginfo('template_directory')?>/template-emailproc.php" method="post" id="mailform" name="mailform">
 <input type="hidden" value="yxstreme" name="name"  />    
     <table width="80%" border="0" cellspacing="0" cellpadding="2" class="formtable" style="margin-top:0px;">
       <tr>
         <td align="right" valign="top">*Name</td>
         <td align="left" valign="top"><span id="sprytextfield1">
         <input type="text" name="txtName" id="txtName" />
         <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></td>
         </tr>
       <tr>
         <td align="right" valign="top">*Email</td>
         <td align="left" valign="top"><span id="sprytextfield2">
         <input type="text" name="txtEmail" id="txtEmail" />
         <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
         </tr>
       <tr>
         <td align="right" valign="top">Company</td>
         <td align="left" valign="top"><label for="txtCompany"></label>
           <input type="text" name="txtCompany" id="txtCompany" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">Address</td>
         <td align="left" valign="top"><label for="txtAddress"></label>
           <input type="text" name="txtAddress" id="txtAddress" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">City</td>
         <td align="left" valign="top"><label for="txtCity"></label>
           <input type="text" name="txtCity" id="txtCity" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">State</td>
         <td align="left" valign="top"><label for="txtState"></label>
           <input type="text" name="txtState" id="txtState" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">Postal Code</td>
         <td align="left" valign="top"><label for="txtPostalCode"></label>
           <input type="text" name="txtPostalCode" id="txtPostalCode" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">Phone</td>
         <td align="left" valign="top"><label for="txtPhone"></label>
           <input type="text" name="txtPhone" id="txtPhone" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">Interested In:</td>
         <td align="left" valign="top"><select name="ddInterest" class="contactformoption" id="ddInterest">
           <option value="null" selected="selected">Please Choose One</option>
           <option value="Buying One Of Our Products">Buying One Of Our Products</option>
           <option value="Pistols">Pistols</option>
           <option value="Rifles or Shotguns">Rifles or Shotguns</option>
           <option value="Collectibles">Collectibles</option>
  <option value="Other">Other</option></select></td>
         </tr>
       <tr>
         <td align="right" valign="top">How did you find our website?</td>
         <td align="left" valign="top">
           <input type="text" name="txtHowFind" id="txtHowFind" /></td>
         </tr>
       <tr>
         <td align="right" valign="top">Comments/Questions</td>
         <td align="left" valign="top"><label for="txtComment"></label>
           <textarea name="txtComments" id="txtComment" cols="60" rows="5"></textarea></td>
         </tr>
       <tr>
         <td align="right" valign="top">&nbsp;</td>
         <td align="left" valign="top"><input type="submit" name="btnSubmit" id="btnSubmit" value="Send" /></td>
         </tr>
       </table>
       
       </form>
  </td>
     </tr>
   </table></center>
</div>
  <!-- InstanceEndEditable -->
    <!-- end .content --></div>
  <!-- end .container --></div>
</body>
<?php wp_footer();?>

<!-- InstanceEnd --></html>

我知道这与 post 方法以及电子邮件的发送位置有关。我将链接更改为使用自定义模板创建的页面。该模板中不同的代码是

<div class="content" id="maincontent"><!-- InstanceBeginEditable name="MainContent" -->
<%  
on error resume next

xname=request.form("txtName")
xemail=request.form("txtEmail")
xcompany=request.form("txtCompany")
xaddress=request.form("txtAddress")
xcity=request.form("txtCity")
xstate=request.form("txtState")
xpostalcode=request.form("txtPostalCode")
xphone=request.form("txtPhone")
xinterest=request.form("ddInterest")
xhowfind=request.form("txtHowFind")
xcomments=request.form("txtComments")

If Request.form("name") = "yxstreme" Then 
    psFrom="no-reply@plugguardstore.com"
    psSubject="Contact from Doug's Guns Website"

   ' message body
   psbody = "<html><head><title>E-mail sent from the Doug's Guns website</title></head>"
   
   psBody="<body><h5>The following e-mail was sent from the Doug's Guns website :</h5>"
   psBody=psBody & "<hr />"
   psBody=psBody & "<p>Name: " & xname & "</p>"
   psBody=psBody & "<p>Email" & xemail & "<br />Company: " & xcompany & "<br />Address: " & xaddress & "<br />"
   psBody=psBody & "City: " & xcity & "<br />State: " & xstate & "<br />Postal Code: " & xpostalcode & "<br />"
   psBody=psBody & "Phone: " & xphone & "<br />"
   psBody=psBody & "Interested In: " & xinterest & "<br /><br />"
   psBody=psBody & "Discovered Website How: " & xhowfind & "<br /><br />"
   psBody=psBody & "Comment/question:<br />" & xcomments & "<br /><br />"

   psBody=psBody & "</body></html>"

   strErr = ""
   bSuccess = False
   'On Error Resume Next 
   'sendCDOHTMLEmail "paul.stybert@gmail.com",psFrom,psSubject,psBody
   sendCDOHTMLEmail "paul.stybert@gmail.com.com",psFrom,psSubject,psBody
   'sendCDONTSHTMLEmail "paul.stybert@gmail.com",psFrom,psSubject,psBody,1
   
   If Err <> 0 Then ' error occurred
     strErr = Err.Description 
     response.write "<center><h3>There was a problem sending your message.</h3></center>"
     'response.write Err.Description
   else
      bSuccess = True
      response.write "<center><h3>Thanks! Someone will be in touch with you shortly.</h3></center>"
   End If
End If


%>
  
  <!-- InstanceEndEditable --><!-- end .content --></div>

我不知道我需要做什么才能完成这项工作。任何帮助,将不胜感激。供您参考,该网站最初是使用 DreamWeaver 创建的,我一直在移动 html 代码并将 php for WordPress 添加到其中。

【问题讨论】:

  • 这是一个简单的表单,找到一些用于创建表单的 WordPress 插件并手动重新创建它。
  • 这段代码看起来像是某种形式的 VB
  • 我尽可能避免使用 Wordpress 插件,但就像@biesior 一样,我实际上建议使用联系表单 - 除了简单的界面,一个好的插件可以处理验证和反垃圾邮件这些天对您来说至关重要的功能。
  • @GetSet 那是因为 ASP 是基于 VB...
  • 有道理。

标签: php html css wordpress


【解决方案1】:

据我了解,您想放弃 asp 处理以使用 Wordpress 解决方案?

除了@biesior gave 关于表单插件(忍者表单、重力表单)的好建议外,在您的情况下,这可以通过将表单的操作部分留空来完成(然后表单将发布到同一页)并在您的模板中处理帖子变量和邮件,就在 get_header() 的上方。您还需要像这样围绕表单内容设置条件:if (!isset($_POST["btnSubmit"]) { ... },这样它就不会显示表单是否已发布。

查看wp_mail 函数。并在该表格中输入nonce,可能还有(re)captcha

但是,表单很麻烦,而且工作量很大,所以请研究一下流行的表单插件之一。您很快就会设置好这个

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 2012-11-01
    • 2014-11-03
    • 2011-02-14
    • 1970-01-01
    • 2021-08-10
    • 2014-03-14
    相关资源
    最近更新 更多