@attikottidetti

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

ラズパイでメール送信ができません。

Q&A

linuxで稼働しているプログラムをラズパイで実行しようとしていますが、メール送信ができずにエラーとなってしまっています。

調べてみたら、以下のような掲載があったので、実行してみましたが、まだ、エラーが出ています。
助言をいただけたら幸いです。
一応、最新の状態にupgradeはしてあります。

RaspberryPIでPHPでメールを送信

2018/07/07 14:15 

php.iniの編集
SMTP_AUTHを使います。
```php5

[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
smtp=「送信サーバ」
smtp_port=587
smtp_username=ユーザー名
smtp_pwd=パスワード

phpのコード
mb_language("Japanese");
mb_internal_encoding("UTF-8");
$i=mb_send_mail("宛先アドレス","タイトル","本文");
?>

ちゃんとできてればこれだけで送信可能。
```

0 likes

1Answer

メールの送信部分は、このような感じで、ubuntuやxserverでは稼働しています。

// 送信元の設定
        $from = $SenderEML;
        $org = '';
        $text = $message;
////////////////////////////////////////////////////////////////////////////////
                    $subject = $title;
// ヘッダー設定
                    $header = '';
                    $header .= "Content-Type: multipart/mixed;boundary=\"__BOUNDARY__\"\n";
                    $header .= "Return-Path: " . $from . " \n";
                    $header .= "From: " . $from . " \n";
                    $header .= "Sender: " . $from . " \n";
                    $header .= "Reply-To: " . $from . " \n";
                    $header .= "Organization: " . $org . " \n";
                    $header .= "X-Sender: " . $org . " \n";
                    $header .= "X-Priority: 3 \n";
// テキストメッセージを記述
                    $body = "--__BOUNDARY__\n";
//    $body .= "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n\n";
                    $body .= "Content-Type: text/html; charset=\"ISO-2022-JP\"\n\n";
                    $body .= $text . "\n";
                    $body .= "--__BOUNDARY__\n";
                    $content_type = mime_content_type($zippathname . '/' . $zipfilename);
// ファイルを添付
                    $body .= "Content-Type: " . $content_type . "; name=\"{$zipfilename}\"\n";
                    $body .= "Content-Disposition: attachment; filename=\"{$zipfilename}\"\n";
                    $body .= "Content-Transfer-Encoding: base64\n";
                    $body .= "\n";
                    $body .= chunk_split(base64_encode(file_get_contents($zippathname . '/' . $zipfilename)));
                    $body .= "--__BOUNDARY__\n";

//メール送信
                    if (mb_send_mail($to, $subject, $body, $header)) {
                        $sosinmsg .= $to . " 添付メールを送信成功です<br>";
                        $delim = ':';
                    } else {
                        $sosinmsg .= $to . " メール送信失敗です<br>";
                    }
                    print $sosinmsg.'<br>';
0Like

Your answer might help someone💌