attikottidetti
@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

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 . " 添付メールを送信成功です
";
$delim = ':';
} else {
$sosinmsg .= $to . " メール送信失敗です
";
}
print $sosinmsg.'
';
```

0Like

Your answer might help someone💌