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

相关推荐
你觉得脆皮鸡好吃吗8 天前
XSS渗透 COOKIE
网络·http·okhttp·网络安全学习
彭于晏Yan11 天前
OkHttp 与 RestTemplate 技术选型对比
java·spring boot·后端·okhttp
JohnnyDeng9411 天前
OkHttp 拦截器链与缓存策略:深度解析网络层的核心机制
okhttp·缓存
胖胖胖胖胖虎12 天前
okhttp Stream Load 含认证请求重定向
starrocks·okhttp
步十人12 天前
【JavaScript】通过AJAX技术让前端发请求到后端
javascript·ajax·okhttp
XiYang-DING12 天前
【Spring】 Ajax
spring·ajax·okhttp
hj104313 天前
fastadmin 开发示例:使用 layer 弹窗实现数据快速录入
okhttp
YF021117 天前
Android App 高效升级指南:OkDownload 多线程断点续传与全版本安装适配
android·okhttp·app
YF021119 天前
深度解构Android OkDownload断点续传
android·数据库·okhttp
右耳朵猫AI22 天前
Python技术周刊 2026年第14周
开发语言·python·okhttp