[英]Sending emails with Mailgun occasionally hangs and doesn't send email
So ive just implmented mailgun into a website for sending contact form info. 因此,我只是将mailgun插入了一个用于发送联系表信息的网站。 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.
这有时会起作用,但是当我按发送时,在chrome左下方的消息“ waiting url ...”中,大多数页面会挂起。
There is no ssl on the server hence the strange mailgun constructor. 服务器上没有ssl,因此是奇怪的mailgun构造函数。
This is my php which is placed just inside the body of my website. 这是我的php,仅放在我网站的主体内。
<?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');
}
?>
This is the form code: 这是表单代码:
<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).
该页面最终将在按下“提交”按钮后重新加载,但未应用标题重定向(这是因为电子邮件未成功发送)。
The php error logs do not show anything going wrong either. php错误日志也不显示任何错误。
Thanks 谢谢
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.
我发现Mailgun拥有IP地址白名单,因此,如果您尚未在其中添加公用IP地址,则将永远无法建立与Mailgun API的连接。 At the moment of writing this answer, the whitelist is present under this link: https://app.mailgun.com/app/account/security/api_keys
在撰写此答案时,此链接下有白名单: https : //app.mailgun.com/app/account/security/api_keys
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.