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

相关推荐
.豆鲨包3 天前
【Android】OkHttp的使用及封装
android·java·okhttp
华科易迅3 天前
Vue通过Ajax获取后台路由信息
vue.js·ajax·okhttp
studyForMokey4 天前
【Android面试】OkHttp & Retrofit 专题
android·okhttp·面试
fLDiSQV1W5 天前
springMVC-HTTP消息转换器与文件上传、下载、异常处理
网络协议·http·okhttp
Ttang239 天前
Java爬虫:Jsoup+OkHttp实战指南
java·爬虫·okhttp
李庆政3709 天前
OkHttp的基本使用 实现GET/POST请求 authenticator自动认证 Cookie管理 请求头设置
java·网络协议·http·okhttp·ssl
无名-CODING10 天前
Java 爬虫进阶:动态网页、多线程与 WebMagic 框架实战
java·爬虫·okhttp
小李云雾11 天前
零基础-从ESS6基础到前后端联通实战
前端·python·okhttp·中间件·eclipse·html·fastapi
亿牛云爬虫专家11 天前
爬虫踩坑实录:OkHttp 接入爬虫代理报 Too many tunnel connections attempted 深度解析
爬虫·okhttp·https·爬虫代理·connect·隧道代理·ip 切换