假设我想将所有代码放在一个自定义页面中,如page-contact.php
如何构造代码以便接收电子邮件?代码在其他PHP项目中也可以使用,但在WordPress环境中出现错误,为什么我只需要页面中的代码来处理表单,却找不到页面
背景
我确实阅读了另一个来源Sitepoint about about WordPress emails 但这是一个很小的项目,我只需要根据项目的设置来完成。在另一个PHP项目中,我需要根据所写内容发送表单操作_contactform.php
<form action="_contactform.php" method="post" name=\'submitform\'>
在那里效果很好。但是,当我在WordPress项目中重用代码时,我遇到了一个错误,即该页面不存在,因为它似乎试图将用户指向urlhttp://example.com/contact/_contactform.php
因此,与其让行动_contactform.php
我想我可以把代码放在同一页上,但我该如何包装它,等等?表单的php文件以以下开头
<?php
/* Set e-mail recipient */
$orderemail = "example@example.com";
$name = check_input($_POST[\'name\']);
$email = check_input($_POST[\'email\']);
$address = check_input($_POST[\'address\']);
$message = "
Hello!
Your contact form has been submitted by:
Name: $name
E-mail: $email
Address:
$address
End of message
";
/* Send the message using mail() function */
mail($orderemail, $subject, $message);