wordpress自定义订阅邮件发送

一、前端代码方法一 Ajax 提交订阅

php 复制代码
<form  id="subscribe-form" class="alert-from-box subscribe-form" method="POST">
						<div><input type="text" name="email" id="sub_email" placeholder="Email address*"><p class="email-error-tips"></p></div>
						<div><input type="text" name="phone" id="sub_phone" placeholder="Phone number"><p class="phone-error-tips"></p></div>
						<div><button type="submit" name="sub_submit">Get My Discount</button></div>
						<input  type="hidden" name="url" value="<?php echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ?>">
                        <input  type="hidden" name="comment_post_ID" value="<?php echo get_the_ID() ?>" id="comment_post_ID"> 
                        <input  type="hidden"name="comment_author_IP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" id="comment_author_IP">
</form>

<script>
jQuery(function($){
    $("#subscribe-form").on("submit", function(e){
        e.preventDefault();
        var data = {
            action: "subscribe_user",
            email: $(this).find('[name="email"]').val(),
            phone: $(this).find('[name="phone"]').val()
        };
        $("#subscribe-msg").html("提交中...");
        $.post("<?php echo admin_url('admin-ajax.php'); ?>", data, function(res){
			if(res.status=='success'){
                    $('#subscribe-form button').text(res.msg);
                    $('#subscribe-form')[0].reset();
                } else {
                    $('.email-error-tips').text(res.msg).css('color','red');
            }
        });
    });
});
</script>

二、前端代码方法二 表单提交订阅

php 复制代码
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
    <input type="hidden" name="action" value="subscribe_user_form">
    
    <label>Email:</label>
    <input type="email" name="email" required>

    <label>Phone (optional):</label>
    <input type="text" name="phone">

    <button type="submit">Subscribe</button>
</form>

三,后端安装插件(https://download.csdn.net/download/qq_39339179/92342838

相关推荐
灵感菇_1 天前
Android OkHttp框架全解析
android·java·okhttp·网络编程
HIT_Weston2 天前
104、【Ubuntu】【Hugo】搭建私人博客:搜索功能(AJAX请求)
ubuntu·ajax·okhttp
雨声不在2 天前
okhttp的自定义dns解析
okhttp·dns
凛_Lin~~4 天前
安卓网络框架——OkHttp源码解析(基于3.14.x)
android·网络·okhttp
岁岁种桃花儿5 天前
XMLHttpRequest 从入门到实战:GET/POST 请求完整案例
ajax·okhttp
月月玩代码6 天前
OkHttp,Square出品的Java/Android HTTP客户端!
android·java·okhttp
m0_748254667 天前
AJAX 基础实例
前端·ajax·okhttp
胖虎18 天前
Android 文件下载实践:基于 OkHttp 的完整实现与思考
android·okhttp·下载文件·安卓下载·安卓中的下载
假装我不帅10 天前
rider开发asp.net webform项目
android·okhttp·asp.net
weixin_5150696610 天前
OkHttp-HTTP 客户端框架
网络协议·http·okhttp·框架