[英]Mail() with attachment file doesn't work (PHP + HTML)
我正在嘗試發送帶有附件文件的 email 但不起作用,我無法接收任何文件。
從語法上講,這似乎是正確的,因為我在任何地方都沒有任何郵件,問題是我沒有收到任何郵件。
這是我的 HTML 代碼:
html>
<head>
</head>
<body>
<form action="hola.php" method="post">
<input type="file" name="csv" id="csv" value="RUN"/><br/>
<input type="submit" value="enviar">
</form>
<body>
</html>
這是我的 PHP 代碼:
$recipient_email = 'prueba@prueba.com';
$subject = "Mensaje de prueba";
$message = "Hola, esto es una prueba";
if (isset($_FILES['csv'])) {
$tmp_name = $_FILES['my_file']['tmp_name'];
$name = $_FILES['my_file']['name'];
$size = $_FILES['my_file']['size'];
$type = $_FILES['my_file']['type'];
$error = $_FILES['my_file']['error'];
$total = count($_FILES['csv']['name']);
for( $i=0 ; $i < $total ; $i++ ) {
$tmpFilePath = $_FILES['csv']['tmp_name'][$i];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$reply_to_email."\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= "From:" . "doc@gestio.aliance-brother.com";
$mensaje .="Content-Type: $file_type; name=".$file_name."\r\n";
$mensaje .="Content-Disposition: attachment; filename=".$file_name."\r\n";
$mensaje .="Content-Transfer-Encoding: base64\r\n";
$mensaje .="X-Attachment-Id: ".rand(1000, 99999)."\r\n\r\n";
$mensaje .= $encoded_content;
mail($recipient_email, $subject, $mensaje, $headers);
}
header('Location: https://' . $servidor . '/home.php');
}
將enctype="multipart/form-data"屬性添加到表單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.