PHPmailerにPDF添付ファイルを追加しようとしていますが、添付ファイルを送信しません。PHPMailerフォームからのLaravel添付ファイルが機能しない
コントローラー:
$recipient = Request::input('emailaddress');
$recipientName = Request::input('name');
$file = Request::input('file');
$mail = new \PHPMailer(true);
try {
$mail->isSMTP();
$mail->CharSet = "utf-8";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.sendgrid.net";
$mail->Port = 587;
$mail->Username = "username";
$mail->Password = "password";
$mail->setFrom("[email protected]", "Business");
$mail->Subject = "Offerte";
$mail->MsgHTML("Test.");
$mail->addAddress($recipient, $recipientName);
if (isset($_FILES[$file]) &&
$_FILES[$file]['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES[$file]['tmp_name'],
$_FILES[$file]['name']);
}
$mail->send();
} catch (phpmailerException $e) {
dd($e);
} catch (Exception $e) {
dd($e);
}
return back()->with('send', 'send');
}
形式:
<form method="POST" action="/offer/sendmail">
<div class="form-group">
<label for="name">Aan:</label>
<input type="text" class="form-control" id="name" name="name" value="{{$offers->name}}">
</div>
<div class="form-group">
<label for="emailaddress">Email-adres:</label>
<input type="text" class="form-control" id="emailaddress" name="emailaddress" value="{{$offers->email}}">
</div>
<div class="form-group">
<label for="subject">Onderwerp:</label>
<input type="text" class="form-control" id="subject">
</div>
<div class="form-group">
<label for="subject">Bericht:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
</div>
<div class="form-group">
<label for="subject">Voeg een bestand toe:</label>
<input type ="file" name='file' id='uploaded_file'>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Verzenden</button>
</form>
それは、電子メールを送信しないが、それには添付ファイルがありません。理由は何ですか?また、$ mail-> usernameとpasswordを変更して、自分の証明書を非公開にすることもできます。
'isset($ _ FILES [$ file])'と '$ _FILES [$ file] ['error'] ==UPLOAD_ERR_OKÉ'の値をデバッグできますか?それはどちらかです。 – milo526
私はまったく新しいPHPですので、ちょっと疑問に思うかもしれません。どうすればデバッグできますか?ちょうどdd? – itvba
それはあなたのログに(正しいファサードをインポートした後に)書き込むために 'Log :: info($ value)'を使うか、 'dump()'を使うか、単に値をエコーすることもできます。 – milo526