1
1

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 php で smtp 送信 ライブラリ無しでもOK

1
Last updated at Posted at 2022-01-12

今回は cakeemail を使用。
メールサーバーってマジで不安定だから大変。
しかも最近はAPI送信とかになっているからsmtpの送信方法が無くて困る。

以下の方法ならアカウントを設定するだけだから
ライブラリとか必要無しで送信できるので便利。

ということで早速方法。

sendgridを利用

まずはメールの設定です


public $default = array(
    'host' => 'smtp.sendgrid.net',//固定
    'port' => 587,//固定
    'transport' => 'Smtp',//固定
    'username' => 'apikey', //固定
    'password' => 'SG.Uxxxxxxxxxxx229',//要変更 パスワード
    'from' => 'you@localhost',//任意
);


こんな感じで固定って書いてあるのは sendgrid の規則に従って書いてください。

たったこれだけで送信できるようになる。

また、接続元のIPアドレスを sendgrid側で制限をしている場合は、
一度メールを送信して、エラーになるとIPが sendgrid に表示されるので、それを allow して送信許可して再度送信してみる。

すると送信できるようなる。

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?