使用PHPMailer,Mailgun和HTTP API发送电子邮件

I Am able to send emails off this web server

I am on a shared web server using godaddy, and it's been awesome for me in a number of ways. I host two aspects of my website on here: a public wordpress site and an employee intranet. That's right, it has two aspects, with my custom built intranet being hosted next to a wordpress site. I CAN send emails.
The way I can send emails is via the Mailgun plugin for wordpress. As far as I can tell, this is the ONLY way my web server is sending emails right now. I have tried PhpMailer and php mail() vanilla, neither of those are doing squat.
I am using mailgun as my mail server, and it's working out pretty well so far. I use the wordpress plugin with ninja forms, and all my submissions to the forms get emailed to my email. The MX entries and txt files are all setup, so that is not my issue.

I was able to send emails with the program when it was hosted locally

I know the emails sent from the intranet are configured correctly, because it worked all day long when hosted locally. When it was hosted locally, I was sending through php mail() [I know, I know, hold your jeers] and it worked fine. When I brought the intranet online however, I started getting zero emails.
go daddy tells me "buzz off" essentially. They say no matter what smtp server I'm pointing to, they see no record of an email trying to be sent through them. No matter what host, no matter what domain, no matter what, they can not see the emails trying to be sent.
I have another mx entry, I believe because of our office 365 email server. This mx entry was brought to my attention because of godaddy. That mx entry points to outlook. From what I can tell, this is clogging my smtp abilities.
How does the mailgun plugin send emails then? Http. I know, I know, this sounds weird. It sounds weird to me too, I can find a whopping one site on the internet that even talks about it, and it's On our site. What it seems to be saying is that you can send the email info via http, which the mail server decodes and emails via smtp. I think this will be the easiest way to send email on my site, as it is what the Mailgun plugin does.

How do I know the Mailgun plugin uses http instead of smtp?

Mailgun Plugin configuration So, the plugin asks for my api key and domain name, nothing else. What I'm HOPING to do is to figure out how to do this with my php code. Phpmailer has no documentation on this that I can find, and Mailgun recommends using Phpmailer or the Wordpress plugin.

I cracked open the plugin, and am very confused

I would describe myself as Php attempting. This is way too much for me. The code I THINK is allowing the plugin to do it's thang is this

public function api_call($uri, $params = array(), $method = 'POST')
{
    $options = get_option('mailgun');
    $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $options['apiKey'];
    $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options['domain'];

    $time = time();
    $url = $this->api_endpoint.$uri;
    $headers = array(
        'Authorization' => 'Basic '.base64_encode("api:{$apiKey}"),
    );

    switch ($method) {
    case 'GET':
        $params['sess'] = '';
        $querystring = http_build_query($params);
        $url = $url.'?'.$querystring;
        $params = '';
        break;
    case 'POST':
    case 'PUT':
    case 'DELETE':
        $params['sess'] = '';
        $params['time'] = $time;
        $params['hash'] = sha1(date('U'));
        break;
    }

    // make the request
    $args = array(
        'method'    => $method,
        'body'      => $params,
        'headers'   => $headers,
        'sslverify' => true,
    );

    // make the remote request
    $result = wp_remote_request($url, $args);
    if (!is_wp_error($result)) {
        return $result['body'];
    } else {
        return $result->get_error_message();
    }
}

If this is not it, the two main files are in the comments, because of my reputation.

Alternative hopes

I understand this might be straight impossible. If it is, i am thinking there are two alternatives, there might be more. The two alternatives I see are sending my emails the way Ninja Form does to this plugin, but I have no clue as to how to go about that. The second is forcing phpmailer through the outlook mx entry, and sending it via smtp. How I would go about this is also beyond me. Any other suggestions or solutions are welcome.

dongtong2021
dongtong2021 我在这里看不到一个清晰,简洁的问题......
3 年多之前 回复
douluan5523
douluan5523 Mailgun.php和wp-mail-api.php
3 年多之前 回复

1个回答



您应该在发布前进行搜索。 GoDaddy阻止出站SMTP,但它们提供了一个可以使用的网关。 这会阻止许多发送方案(例如GoDaddy未通过SPF检查)。 MX记录与出站</ em>邮件完全无关。</ p>

您可以将PHPMailer与MailGun等HTTP服务一起使用,以便为您构建消息。 像在PHPMailer中一样构建消息,然后调用 preSend()</ code>和 getSentMIMEMessage()</ code>而不是 send()</ code>。 然后,您将收到一条完整的消息,您可以将其提交给HTTP API。</ p>
</ div>

展开原文

原文

You should search before posting. GoDaddy blocks outbound SMTP, but they provide a gateway that you can use instead. This blocks many sending scenarios (such as GoDaddy failing SPF checks). MX records have absolutely nothing to do with outbound mail.

You can use PHPMailer with HTTP services like MailGun by using it to construct messages for you. Build your message as you would normally in PHPMailer, then call preSend() and getSentMIMEMessage() instead of send(). You will then have a complete message you can submit to the HTTP API.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐