1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

sendgrid で 許可IP を php から追加

Posted at

sendgridを利用し、IPをホワイトリストに追加して利用するのはセキュリティ上必須である。

しかし、接続元のIP設定を間違えたり、
モデムを変更した場合などログインできなくなる。

上記の場合は api_key を用いて
php から ip アドレスを追加してログインできるようにしよう。

前提として当該サーバーからはメールを送信できる状態である。
(認証済み)

参考
https://github.com/sendgrid/sendgrid-php/blob/main/examples/accesssettings/accesssettings.php

hoge.php

$sg = new SendGrid(env('SENDGRID_API_KEY'));

$request_body = json_decode('{
"ips": [
    {
        "ip": "82.122.28.23"
    },
    {
        "ip": "37.126.154.*"
    }
    ]
}');

try {
    $response = $sg->client->access_settings()->whitelist()->post($request_body);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}


これで指定したIPをホワイトリストに追加することが可能。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?