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 5 years have passed since last update.

TaskBoardをNginxで使った時にメールが送信できない時の対処方法

Last updated at Posted at 2016-05-02

はじめに

TaskBoardは、実にシンプルで便利。(と言いましても使い始めたばかり)
Redmineを使っていたのですが、どうも、自分の開発手法と合わないと思っていた矢先に発見。
しかもslimを使用しているおかげで動作が早い気がする。
しかしながら、Nginxを使っていた私として困ったことが…

問題

メーラーの動作待ちなのか次の画面に移動せずF5かESCでしか戻れない
メールの設定をしたのにめーるが届かない

エラー探し

Nginxのエラーログを見てみると…以下の様なエラーが。

/var/log/nginx/error.log
2016/05/02 14:45:41 [error] 14983#0: *1983 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Call to undefined function apache_request_headers() in /usr/share/nginx/TaskBoard/api/mailFactory.php on line 5" while reading response header from upstream, client: 61.115.***.***, server: task.*********.com, request: "POST /api/boards/3/items HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "task.*********.com", referrer: "https://task.*********.com/"

いろいろと探しまわった結果 APACHE_REQUEST_HEADERS がどうやら張本人のようです。

修正

TaskBoard/api/mailFactory.php
function getServerHost() {
    //$headers = apache_request_headers(); //←コメントアウト
    $headers = getallheaders(); //←追加
    foreach($headers as $header => $value) {
        if (strtolower($header) == 'host') {
            return $value;
        }
    }
}

結果

文字化けしながらも届いた。

メール
ozy-san created new item at board ******:
ページデザイン
ユーザーインターフェイス

Unassigned
0

2
Navigate to board!

文字化けを直す

どうやら、PHPMailerでの文字コード設定が必要なようです。
以下のように修正

TaskBoard/api/mailFactory.php
function createMailObject() {
    global $MAIL_HOST, $MAIL_USERNAME, $MAIL_PASSWORD, $MAIL_SMTPSECURE, $MAIL_PORT, $MAIL_FROM, $MAIL_FROMNAME;

    $mail = new PHPMailer;

    $mail->isSMTP();
    $mail->Host = $MAIL_HOST;
    $mail->SMTPAuth = true;
    $mail->Username = $MAIL_USERNAME;
    $mail->Password = $MAIL_PASSWORD;
    $mail->SMTPSecure = $MAIL_SMTPSECURE;
    $mail->Port = $MAIL_PORT;

    $mail->From = $MAIL_FROM;
    $mail->FromName = $MAIL_FROMNAME;
    $mail->CharSet = "UTF-8"; // 追加
    return $mail;
}

最後に

ソースコードもシンプルでエラーが追いやすい。
機能もシンプル使いやすい。
あとは、このBootstrapのテーマが入れ替えられれるようになっていれば最高なんだけれども、ここは我慢でしょうか。

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?