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

相关推荐
qq_406176144 天前
JavaScript的同步与异步
前端·网络·tcp/ip·ajax·okhttp
A24207349305 天前
深入浅出理解AJAX:核心原理与POST/GET区别详解
前端·ajax·okhttp
吃喝不愁霸王餐APP开发者7 天前
使用OkHttp连接池优化高频调用美团API的网络资源复用效率
okhttp
chilavert3188 天前
技术演进中的开发沉思-266 Ajax:让 动画优化
javascript·ajax·okhttp
chilavert3188 天前
技术演进中的开发沉思-268 Ajax:JSON
javascript·ajax·okhttp·json
网络风云9 天前
AJAX与Fetch--异步Web请求的深度对比
前端·ajax·okhttp
教练、我想打篮球13 天前
120 同样的 url, header, 参数, 使用 OkHttp 能够成功获取数据, 使用 RestTemplate 报错
http·okhttp·resttemplate·accept
chilavert31813 天前
技术演进中的开发沉思-258 Ajax:自定义事件
前端·ajax·okhttp
chilavert31813 天前
技术演进中的开发沉思-259 Ajax:浏览器历史管理
javascript·ajax·okhttp·状态模式
C1829818257515 天前
HttpURLConnection 是 Apache HttpClient 和 OKHttp 底层吗
okhttp·apache