0
我試圖在我的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->用戶名和密碼,所以我可以保持我的憑據私人。
你可以調試'isset($ _ FILES [$ file])'& '$ _FILES [$ file] ['error'] ==UPLOAD_ERR_OKÉ'的值,顯然其中一個是錯誤的,我們需要檢查哪一個是。 – milo526
也許是一個愚蠢的問題,因爲我有點新到PHP。我如何調試?只是一個dd? – itvba
這可能是一種方法,你也可以使用'Log :: info($ value)'寫入你的日誌(在導入正確的外觀之後)或者使用'dump()'或者簡單地回顯我使用過的值 – milo526