【发布时间】:2016-04-14 10:08:12
【问题描述】:
我为这个 HTML 和一个相应的 PHP 创建了两个脚本。
HTML 标记:
<html>
<body>
<form action="http://senindiaonline.in/admar/non-series-numbers-db.php" method="post" target="_blank" name="non_series_numbers_db" enctype="multipart/form-data">
<label for="emp-id">Employee ID: </label>
<input type="text" name="emp-id" id="emp-id" maxlength="15" style='text-transform:uppercase'/>
<br/>
<label for="no-csv">If you have a mobile number database in CSV file format upload that here: </label>
<input name="no-csv" id="no-csv" type="file" accept=".csv"/>
<br/>
<label for="no-xls">If you have a mobile number database in XLS (excel) file format upload that here: </label>
<input name="no-xls" id="no-xls" type="file" accept=".xls"/>
<br/>
<label for="no-xlsx">If you have a mobile number database in XLSX (excel) file format upload that here: </label>
<input name="no-xlsx" id="no-xlsx" type="file" accept=".xlsx"/>
<br/>
<input name="send" value="Send" type="submit" id="send"/>
</form>
</body>
</html>
PHP 脚本:
<?php
error_reporting(0);
$email_to = 'senindiagroup@gmail.com';
$email_subject = "Non-Seriesed Mobile Number Database from Ad&Marketing Employee Panel of Sen India Online inc.";
$emp_id = $_POST['emp-id'];
$sub="Employee ID: $emp_id";
$bound_text = "jimmyPI23";
$bound = "--" .$bound_text. "\r\n";
$bound_last = "--" .$bound_text. "--\r\n";
$email_message .= "If you can see this MIME than your client doesn't accept MIME types! \r\n" .$bound;
$email_message .= "Content-Type: text/html; Charset=\"iso-8859-1\"\r\n" ."Content-Transfer-Encoding: 7bit\r\n\r\n" ."$sub\r\n" .$bound;
//getting temporary file location with name
$a=file_get_contents($_FILES['no-csv']['tmp_name']);
$b=file_get_contents($_FILES['no-xls']['tmp_name']);
$c=file_get_contents($_FILES['no-xlsx']['tmp_name']);
//getting original name of the file you uploaded
$name=$_FILES["no-csv"]["name"];
$name1=$_FILES["no-xls"]["name"];
$name2=$_FILES["no-xlsx"]["name"];
$email_message .= "Content-Type: {\"application/octet-stream\"}; \n" . "name=\"$name\ "\n" . "Content-Transfer-Encoding: base64\r\n" ."Content-Disposition: attachment; \n" . " filename=\"$name\ "\n"."\r\n" .chunk_split(base64_encode($a)).$bound;
mail($email_to, $email_subject, $email_message, $headers);
?>
错误是:
第 31 行显示语法错误,使用邮件命令附加文件。
并且邮件没有发送。我用 DreamWeaver 的建议解决了这个错误。然后发送邮件,但邮件中不包含附件。
【问题讨论】:
-
我刚刚用谷歌搜索并得到了这个链接:stackoverflow.com/questions/12301358/…
-
我用正确的 HTML 元素标签 'label' 替换了所有的 'lebel' 标签。
-
说真的...停止尝试使用
mail()发送附件。可以做到,但您需要编写大量代码。相反,只需下载 phpMailer 或 Swiftmailer,并使用其中之一。他们已经为您完成了所有工作,因此您只需将他们包括在内并给他们打电话。它们还解决了发送电子邮件的许多安全问题,并且比简单的mail()功能具有额外的功能,例如能够通过外部 smtp 服务器发送。