首页 文章

如何通过表单发送POST请求,同时还发送表单内容的电子邮件?

提问于
浏览
0

我有一个由Mailchimp(电子邮件活动服务)创建的表单,允许用户订阅时事通讯 . 我希望在表单提交后发送表单内容的电子邮件并发布原始表单操作 .

我已经使用php mail()函数从这个链接中取得了这个,并且它工作正常:Send email with PHP from html form on submit with the same script

但我不知道如何从我的订阅表单中提交原始帖子:

<form action="http://mailchimpurl.com/subscribe/post" method="POST">

我想再次发送表单内容的电子邮件,并发送订阅发布请求 .

谢谢您的帮助!

4 回答

  • 0

    对于任何表单来说,提交到一个 endpoints 和一个 endpoints 通常更好 .

    将操作设置为指向您自己的服务器 . 然后让处理请求的程序执行两个不同的操作(顺序) .

  • 0

    如果您的操作指向您无法添加任何php mail()或类似的位置,我会考虑使用JS / jQuery / ajax触发此客户端 .

    var sendEmail = 'youremailpage.php?email=you@youremail.com&subject=....'
    
    $("#submit").click(function(){
      // use ajax to trigger an external php file with mail()
      $.ajax({ url: sendEmail, data: {action: sendEmail}, type: "post", success: function(output) {  } }); 
     });
    

    在PHP文件中,我只需使用 $_GET('email') 等拉出所有url参数...

    thisthis之类的东西类似于usint $ .post,但我没有自己测试过它们 .

  • 0
    $('#yourform').submit( function(ev) {
        ev.preventDefault(); //stop form submitting
    
        theform = this;
    
        $.post( "example.php", $(this).serialize()).done(function() {
            theform.submit();
        });
    
    });
    
  • 0

    我找到了解决这个问题的方法 . 使用PHP CURL,我能够发送一个帖子请求到我的mailchimp网址 . 这是我用过的博客文章的链接 .

    http://davidwalsh.name/curl-post

相关问题