# PHPMailer+Gmailによるユーザアカウント認証

**URL:** <https://forum.ficusonline.com/t/topic/348>\
**Category:** WEB Design\
**Created:** [2020 年 2 月 10 日午前 1:28 UTC](https://forum.ficusonline.com/t/topic/348 "2020-02-10T01:28:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2020 年 2 月 10 日午前 1:28 UTC](https://forum.ficusonline.com/t/topic/348/1 "2020-02-10T01:28:07Z")

</div>

Linphone(Flexisip)等の登録型アプリのユーザ認証方式をGmailのSMTPサーバを利用したEmail認証にするためPHPMailerを導入。Userfrostingには標準装備されていますが、Flexisipのアカウントマネージャーとして構築したxmlrpcサーバにも導入します。

自前のメールサーバを運用している場合は、PHPのmail関数によるsendmailを使用する方法が一般的です。

**PHPMailer**  
[https://github.com/PHPMailer/PHPMailer](https://github.com/PHPMailer/PHPMailer)

**リファレンス**  
[http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html](http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html)

必要な機能だけを盛込んだファイルだけをアプリのフォルダにコピーするだけでインストールできますが、ソースとなるファイルが少ないのでComposerによりインストールします。

サーバのルートフォルダ（Flexisipのxmlrpcサーバ）で以下コマンドを実行します。

```auto
$ sudo composer require phpmailer/phpmailer

```

GmailのSMTPサーバを利用したサンプルコードが用意されています。

> <https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps>

Gmailの2段階認証を利用する場合には、PHP拡張モジュールが必要となるので、GithubのComposer.jsonの中身も確認して下さい。

Flexisipのアカウントマネージャーへの導入方法についてはブログ記事で報告します。

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2020 年 2 月 10 日午前 1:58 UTC](https://forum.ficusonline.com/t/topic/348/2 "2020-02-10T01:58:27Z")

</div>

カスタムヘッダー追加による **Content-Type: multipart/alternative** の設定（Textとhtmlフォーマットによる送信）

```auto
$limite = "_----------=_parties_".md5(uniqid (rand()));
$mail->addCustomHeader('Content-Type: multipart/alternative; boundary="'.$limite.'"');

$message = "";

	$message .= "--".$limite."\n";
	$message .= "Content-Type: text/plain; charset=\"utf-8\"\n";
	$message .= "Content-Transfer-Encoding: 8bit\n\n";
	$message .= $text;

	$message .= "\n\n--".$limite."\n";
	$message .= "Content-Type: text/html; charset=\"utf-8\"\n";
	$message .= "Content-Transfer-Encoding: 8bit;\n\n";
	$message .= $html;

	$message .= "\n--".$limite."--";

```

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2020 年 2 月 11 日午前 1:47 UTC](https://forum.ficusonline.com/t/topic/348/3 "2020-02-11T01:47:04Z")

</div>

> <https://stackoverflow.com/questions/32743260/send-email-asynchronously-via-phpmailer/32745183#32745183>
