wordpress 如何从wordpress中的表单发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10927682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send e-mail from form in wordpress
提问by saad iqbal
I am new in programing and WordPress. I want to send a e-mail from my form with a message, phone, ect. Can anyone tell me how can i do that? Here is my code so far...
我是编程和 WordPress 的新手。我想从我的表单发送一封带有消息、电话等的电子邮件。谁能告诉我我该怎么做?到目前为止,这是我的代码...
<div id="form">
<?php
add_filter('wp_mail_content_type','set_content_type');
function set_content_type($content_type){
return 'text/html';
}
?>
<div id="name">
<p id="username"> Name: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Email: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Phone: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Message: </p>
<input type="text" name="message" class="textarea">
</div>
<input type="button" value="SEND" id="btn">
</div>
回答by Vijaya Narayanasamy
To send mail from a form with following fields, open a new file and copy these lines and save (e.g. mail.php):
要从具有以下字段的表单发送邮件,请打开一个新文件并复制这些行并保存(例如 mail.php):
<?php
//sending mail
if(isset($_POST['sub']))
{
$uname=$_POST['uname'];
$mailid=$_POST['mailid'];
$phone=$_POST['phone'];
$message=$_POST['message'];
mail($uname,$mailid,$phone,$message);
if(mail($uname,$mailid,$phone,$message))
{
echo "mail sent";
}
else
{
echo "mail failed";
}
}
?>
<form name="frm" method="post" action="#">
<label for="uname">Name:</label>
<input type="text" value="" name="uname" id="uname"><br/>
<label for="mailid">Email:</label>
<input type="text" value="" name="mailid" id="mailid"><br/>
<label for="mobile">Phone:</label>
<input type="text" value="" name="phone" id="phone"><br/>
<label for="message">Message:</label>
<input type="text" value="" name="message" id="message"><br/>
<input type="submit" value="Submit" name="sub" id="sub">
</form>
回答by Foxinni
It will have to be much morecomplicated than what you have at the moment.
这将不得不更不是你有什么,此刻复杂。
My first recommendationwould be to use some, rather top-heavy, form plugins, But you will save yourself a lot of time and trouble like that.
我的第一个建议是使用一些头重脚轻的表单插件,但是这样可以为自己节省大量时间和麻烦。
http://www.deliciousdays.com/cforms-plugin/
http://www.deliciousdays.com/cforms-plugin/
http://wordpress.org/extend/plugins/contact-form-7
http://wordpress.org/extend/plugins/contact-form-7
My 2nd recommendationwould be to follow a popular tutorial for a full custom form to email script.
我的第二个建议是遵循一个流行的教程,将完整的自定义表单发送到电子邮件脚本。
http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme
http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme
Note:Beware of spam bots and various other possible dangers of just putting a public form up on the web. If's very possible that you will have a hole in your custom code and a couldcause some damage if exploited by the right person.
注意:当心垃圾邮件机器人和其他各种可能的危险,因为只是在网络上放置公共表格。如果您的自定义代码中很可能存在漏洞,并且如果被合适的人利用可能会造成一些损害。