【发布时间】:2017-09-29 07:20:50
【问题描述】:
我编写了这段代码,用于从 html 格式发送带有 php 附件的电子邮件:
<?php
if($_POST && isset($_FILES['file-upload'])){
$from = $_POST["email"];
$rubinetteria = 'info@domain.com';
$nome = filter_var($_POST["nome"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_STRING);
$oggetto = filter_var($_POST["oggetto"], FILTER_SANITIZE_STRING);
$compagnia = filter_var($_POST["company"], FILTER_SANITIZE_STRING);
$ruolo = filter_var($_POST["ruolo"], FILTER_SANITIZE_STRING);
$messaggio = filter_var($_POST["messaggio"], FILTER_SANITIZE_STRING);
$fileTmpName = $_FILES['file-upload']['uploads'];
$fileName = $_FILES['file-upload']['name'];
$fileSize = $_FILES['file-upload']['size'];
$fileType = $_FILES['file-upload']['type'];
$fileError = $_FILES['file-upload']['error'];
$handle = fopen($fileTmpName, "r");
$content = fread($handle, $fileSize);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("sanwebe");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$compagnia."\r\n";
$headers .= "Reply-To: ".$reply_to_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= "<b>Azienda: </b>" .$compagnia. "<br>";
$body .= "<b>Nome e Cognome: </b>" .$nome. "<br>";
$body .= "<b>Ruolo: </b>" .$ruolo. "<br>";
$body .= "<br>". chunk_split(base64_encode($messaggio));
$body .= "--$boundary\r\n";
$body .="Content-Type: $fileType; name=".$fileName."\r\n";
$body .="Content-Disposition: attachment; filename=".$fileName."\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
$sentMail = @mail($rubinetteria, $oggetto, $body, $headers);
}
?>
问题是当我收到电子邮件时,有些邮件是加密的。 我猜问题是这行代码:
$body .= "<br>". chunk_split(base64_encode($messaggio));
我试图用这个订阅这一行:
$body .= "<br>".$messaggio;
但在这种情况下,邮件没有加密但没有附件文件(说明确认附件实际上已处理但未收到)
【问题讨论】:
-
“加密”是什么意思?你有例子吗?
-
你应该停止使用 php 的
mail()并查看 phpmailer 或 swiftmailer -
您的问题不清楚。您需要回复 cmets 或 Martin's answer。
-
$headers .= "From:".$compagnia."\r\n";这是不正确的。mail()需要一个电子邮件地址,而不仅仅是一个“公司”名称。这可能在其中发挥了重要作用。 -
OP 的表单上可能也没有 CSRF,或者上述电子邮件发送脚本上没有任何形式的重复预防......