[英]Email attachments not working in PHP
我試圖在我的網站上添加一項功能,該功能允許用戶在發送電子郵件時添加附件。 我用PHP嘗試過,但是代碼不起作用。 它既沒有上傳附件,也沒有在數據庫中插入附件的URL,也沒有回顯確認消息。
除附件外,所有其他表單代碼均已成功處理。 請建議我對代碼進行哪些更改:
PHP:
if (isset($_POST['attachment']))
{
if ($_FILES['file']['size'] > 52428800)
{
$attachment_results = "Sorry, your attachment could not be processed as it is exceeding the limit of 50 MB.";
}
else
{
if ($_FILES["file"]["error"] > 0)
{
$attachment_results = "Sorry, your attachment could not be processed due to some error. Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$attachment_results = "Your attachment was also processed successfully.<br>
File name: " . $_FILES['file']['name'] . "<br>Attachment Size: " . $_FILES['file']['size'];
$destination = "attachments/" . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['name'], $destination);
$url = "https://$domain_name/$destination";
}
}
echo $attachment_results;
}
在腳本的后面,將$url
插入MySQL數據庫,但這也不起作用。 在數據庫中僅插入一個空白變量。
這是HTML代碼:
<form enctype="multipart/form-data" method="post" action="">
<input type="file" name="attachment" style="color: #000000;"><label>(Maximum 50 MB) </label>
<!-- Other Form Code -->
</form>
<?php
if (isset($_POST['submit']))
{
print_r($_FILES);
if ($_FILES['attachment']['size'] > 52428800)
{
$attachment_results = "Sorry, your attachment could not be processed as it is exceeding the limit of 50 MB.";
}
else
{
if ($_FILES["attachment"]["error"] > 0)
{
$attachment_results = "Sorry, your attachment could not be processed due to some error. Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$attachment_results = "Your attachment was also processed successfully.<br>
File name: " . $_FILES['attachment']['name'] . "<br>Attachment Size: " . $_FILES['file']['size'];
$destination = "attachments/" . $_FILES['attachment']['name'];
move_uploaded_file($_FILES['attachment']['tmp_name'], $destination);
$url = "https://$domain_name/$destination";
}
}
echo $attachment_results;
}
?>
<form enctype="multipart/form-data" method="post" action="">
<input type="file" name="attachment" style="color: #000000;"><label>(Maximum 50 MB) </label>
<input type="submit" name="submit">
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.