ソースを参照

少し変更した

pull/16/head
コミット
92c2bcf22a
  1. 2
      .env.example
  2. 4
      app/Http/Controllers/Home/Contact.php
  3. 27
      app/Http/Controllers/MailerController.php
  4. 4
      config/mail.php

2
.env.example

@ -45,6 +45,8 @@ MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_NOREPLY_USER=null
MAIL_NOREPLY_PASS=null
MAIL_ENCRYPTION=null
MAIL_OWNER_ADDRESS=null
MAIL_OWNER_NAME="${APP_NAME}"

4
app/Http/Controllers/Home/Contact.php

@ -87,7 +87,7 @@ class Contact {
// 文章
if (!isset($this->field['bunsyo']) || is_null($this->field['bunsyo']) || $this->field['bunsyo'] == '') $err[] = '文章をご入力下さい。';
if (str_contains($this->field['bunsyo'], 'http://') || str_contains($this->field['bunsyo'], 'https://')) $err[] = '文章でURLを入らないで下さい。';
$this->field['bunsyo'] = $gpg->encrypt(trim($this->field['bunsyo']));
$this->field['bunsyo'] = $gpg->encrypt(trim("メール: ".$this->field['adr']."\n\n".$this->field['bunsyo']));
// 連絡ルール
if (!$this->field['ruleapply']) $err[] = 'ルールを同意して下さい。';
@ -110,7 +110,7 @@ class Contact {
// メールを送る
try {
$mail = new MailerController();
if (!$mail->compose($this->field)) {
if (!$mail->compose($this->field, true)) {
Storage::disk('public')->delete($this->field['filename']);
return view('pages.site.contact', ['field' => $this->field, 'err' => ['送信に失敗しました。数時間後もう一回送信してみて下さい。']]);
}

27
app/Http/Controllers/MailerController.php

@ -13,22 +13,27 @@ use PHPMailer\PHPMailer\Exception;
class MailerController extends Controller {
public function __construct() {}
public function compose ($val) {
public function compose ($val, $form=false) {
mb_language('japanese');
mb_internal_encoding('UTF-8');
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 1;
// $mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = config('mail.mailers.smtp.host');
$mail->Port = config('mail.mailers.smtp.port');
$mail->SMTPSecure = config('mail.mailers.smtp.encryption');
$mail->SMTPAuth = true;
$mail->From = config('mail.owner.address');
$mail->Username = config('mail.mailers.smtp.username');
$mail->Password = config('mail.mailers.smtp.password');
$mail->From = config('mail.'.($form ? 'owner' : 'from').'.address');
$mail->FromName = mb_encode_mimeheader(config('mail.mailers.smtp.'.($form ? 'fromname' : 'noreplyfrom')), 'JIS');
$mail->Username = config('mail.mailers.smtp.'.($form ? 'username' : 'noreplyuser'));
$mail->Password = config('mail.mailers.smtp.'.($form ? 'password' : 'noreplypass'));
$mail->AddAddress(config('mail.owner.address'));
$mail->addReplyTo(config('mail.owner.address'), config('mail.owner.name'));
$mail->AddAddress(config('mail.'.($form ? 'owner' : 'from').'.address'));
if ($form) $mail->addReplyTo(config('mail.owner.address'), config('mail.owner.name'));
else $mail->addReplyTo($val['adr']);
$mail->SMTPOptions = [
'ssl' => [
@ -45,13 +50,15 @@ class MailerController extends Controller {
}
if (isset($val['gpg'])) {
$mail->AddStringAttachment($val['gpg'], $val['gpgname']);
$mail->AddStringAttachment($val['gpg'], $val['filename']);
$mail->AddStringAttachment($val['bunsyo'], $val['adr'].'.gpg');
}
$mail->isHTML(false);
$mail->Subject = '【'.$val['catname'].'】'.$val['kenmei'];
$mail->Body = "メール:".$val['adr']."\n\n".$val['bunsyo'];
$mail->Subject = mb_encode_mimeheader('【'.$val['catname'].'】'.$val['kenmei'], 'JIS');
if ($form) $mail->Body = mb_convert_encoding($val['bunsyo'], 'UTF-8');
else $mail->Body = mb_convert_encoding($val['bunsyo'], 'JIS');
if (!$mail->send()) {
Log::critical('Mailer error: ' . $mail->ErrorInfo);

4
config/mail.php

@ -39,8 +39,12 @@ return [
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'fromname' => env('MAIL_OWNER_NAME'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'noreplyfrom' => env('MAIL_FROM_NAME'),
'noreplyuser' => env('MAIL_NOREPLY_USER'),
'noreplypass' => env('MAIL_NOREPLY_PASS'),
'sendmail' => '/usr/sbin/sendmail -bs',
'timeout' => null,
'auth_mode' => null,

読み込み中…
キャンセル
保存