并且不发送电子邮件

并且不发送电子邮件

本文介绍了使用Mailgun发送电子邮件有时会挂起,并且不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我只是将mailgun插入了一个用于发送联系表信息的网站.这有时会起作用,但是当我按chrome左下角的消息正在等待 url ..."时,大多数页面会挂起.

So ive just implmented mailgun into a website for sending contact form info.This works some of the time, but mostly the page hangs when i press send with the message "waiting for url..." in the bottom left of chrome.

服务器上没有ssl,因此是奇怪的mailgun构造函数.

There is no ssl on the server hence the strange mailgun constructor.

这是我的php,位于我的网站正文中.

This is my php which is placed just inside the body of my website.

<?php

        require 'mailgun-php/vendor/autoload.php';
        use Mailgun\Mailgun;

        if(isset($_POST['register'])){
            $message = "Contact Form.\n\n".
                "Name: ".$_POST['name']."\n".
                "Email: ".$_POST['email']."\n".
                "Message: ".$_POST['message']."\n";

            $mg = new Mailgun(*my key*, "api.mailgun.net", "v2", false);
            $domain = *my domain*;

            $mg->sendMessage($domain, array(
                'from'=>'Contact Form <build@<url>>',
                'to'=> *email*,
                'subject' => ' Contact Form',
                'text' => $message
                )
            );
            header('Location: ?sent=1');
        }

    ?>

这是表单代码:

<form method="post" action="index.php">

    <div class="row 50%">
        <div class="6u 12u$(mobile)"><input type="text" class="text" name="name" placeholder="Name" /></div>
        <div class="6u$ 12u$(mobile)"><input type="text" class="text" name="email" placeholder="Email" /></div>
        <div class="12u$">
            <textarea  name="message" placeholder="Message"></textarea>
        </div>
        <div class="12u$">
            <button class="button" type="submit" name="register"> Send Message </button>
        </div>
    </div>

</form>

未发送电子邮件时,我没有收到任何错误消息.在按下提交"按钮后,页面最终将重新加载,但没有应用标题重定向(这是因为电子邮件未成功发送).

I'm not getting any errors when the email is not sent. The page will eventually reload after the submit button is pressed but the header redirect is not being applied (which im assuming is because the email was not sent successfully).

php错误日志也没有显示任何错误.

The php error logs do not show anything going wrong either.

谢谢

推荐答案

也许这是一个(很晚)的答案,但是我遇到了同样的问题.我发现Mailgun拥有IP地址白名单,因此,如果您尚未在其中添加公用IP地址,则将永远无法建立与Mailgun API的连接.在撰写此答案时,此链接下存在白名单: https://app.mailgun.com/app/account/security/api_keys

Maybe that's a (very) late answer, but I've just met the same problem. And I discovered, that Mailgun has whitelist of IP addresses, so in case you haven't added there your public IP address, the connection to Mailgun's API will never be established.At the moment of writing this answer, the whitelist is present under this link: https://app.mailgun.com/app/account/security/api_keys

这篇关于使用Mailgun发送电子邮件有时会挂起,并且不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:22