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

相关推荐
vistaup18 小时前
OKHTTP 默认构建包含 android 4.4 的TLS 1.2 以及设备时间不对兼容
android·okhttp
bug-0078 天前
关于前后端自动携带cookie跨域问题
okhttp
weixin_440784119 天前
Java线程池工作原理浅析
android·java·开发语言·okhttp·android studio·android runtime
weixin_440784119 天前
OkHttp使用指南
android·java·okhttp
闻哥10 天前
从 AJAX 到浏览器渲染:前端底层原理与性能指标全解析
java·前端·spring boot·ajax·okhttp·面试
猿小羽11 天前
OkHttp vs Retrofit 技术分析报告 - 1769404939594
http·okhttp·retrofit·csdn
AylKfTscDFw12 天前
EtherCAT总线轴控制,大型非标组装检测设备成熟设备程序,注释非常详细,组合应用日本进口机...
okhttp
龙信科技15 天前
【国内电子数据取证厂商龙信科技】Charles的简单介绍及基本配置
科技·okhttp
Filotimo_15 天前
那在HTML中,action是什么
前端·okhttp·html
灵感菇_17 天前
Android OkHttp框架全解析
android·java·okhttp·网络编程