使用MailGun创建邮件列表订阅链接

使用MailGun创建邮件列表订阅链接,mailgun,Mailgun,我在一个私人php heroku repo上,希望创建一个表单,允许我网站上的用户输入他们的电子邮件地址,提交表单,并将电子邮件添加到mailgun上的现有邮件列表中 我已经联系了MailGun支持部门,他们说这是可能的,并查看了文档 这些文件模糊不清,我自己也弄不清楚 您是否可以给我一些代码示例,为我指明正确的方向?这是您的思路: *步骤1-创建一个包含电子邮件列表的邮件列表。 *第2步-创建一个表单,要求用户提供其电子邮件地址,要求用户确认其电子邮件的使用,向给定地址发送电子邮件地址以确认订

我在一个私人php heroku repo上,希望创建一个表单,允许我网站上的用户输入他们的电子邮件地址,提交表单,并将电子邮件添加到mailgun上的现有邮件列表中

我已经联系了MailGun支持部门,他们说这是可能的,并查看了文档

这些文件模糊不清,我自己也弄不清楚


您是否可以给我一些代码示例,为我指明正确的方向?

这是您的思路: *步骤1-创建一个包含电子邮件列表的邮件列表。 *第2步-创建一个表单,要求用户提供其电子邮件地址,要求用户确认其电子邮件的使用,向给定地址发送电子邮件地址以确认订阅。 *

步骤1

# Include the Autoloader file (see documentation on how to install the php wrapper)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client. Use your APIKey
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0l');

# Issue the call to the client.
$result = $mgClient->post("lists", array(
    'address'     => 'my-user-list@mydomain.org',
    'description' => 'A List of users'
));
这将创建一个名为“用户列表”的列表,可以使用“我的用户”在内部访问该列表-list@mydomain.org"

**步骤2**

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Widget</title>

</head>
<body>
    <form action="contact.php" method="POST" onsubmit="return check_the_box()">
        <input name="email" type="text" required="yes">
        <a href="#">I've read and agree to the ToS </a>
        <input id="chx" type="checkbox">
        <button type="submit" >Submit</button>
        <span style="display: none" id="pls"> Please check the Terms of Service box</span>
    </form>
    <script type="text/javascript">
    var box = document.getElementById("chx");
    var alrt = document.getElementById("pls");
    function check_the_box(){
        if(!box.checked) {
            alrt.setAttribute("style","display: inline");
            return false

        }
        else {
    return true
        }

    }
</script>
</body>
</html>
完成了

您所需要做的就是创建每个用户都独有的生成代码,这样做:

function makeConfirmation($newguy) {
    $confirmCode = md5($newguy.'somestringonlyknowntome');
    return $confirmCode;
}
最后,在将他添加到邮件列表之前,当他单击确认电子邮件时,我确认URL中发送给我的服务器的参数

function checkConfirmation($conf,$email) {
    if($conf== md5($email.'somestringonlyknowntome')) {
        return true;
    } else { return false; }
}
相应地编辑

此外:

这里有一个很好的教程,可以在Mailgun的PHP github存储库中找到

祝你好运,如果你成功了,请告诉我!:)
我很想收到你的来信,并在mailgun上写一篇关于这个的博客

'到'=>'GUYWHOSIGNEDUP@hisdomain.com“,”html“=>”请单击此链接确认您想成为我列表的一部分\'>确认''地址'=>'GUYWHOSIGNEDUP@hisdomain.com',--如何为这些地址创建一个唯一的字符串以使脚本可行?通过对emailaddress进行散列,并将其与您只知道的salt字符串连接,生成唯一的字符串
function makeConfirmation($newguy) {
    $confirmCode = md5($newguy.'somestringonlyknowntome');
    return $confirmCode;
}
function checkConfirmation($conf,$email) {
    if($conf== md5($email.'somestringonlyknowntome')) {
        return true;
    } else { return false; }
}