Php 附件在邮件功能wordpress中不起作用
文本邮件工作正常,但我也想附加文件。 附件不起作用。 我的代码是:Php 附件在邮件功能wordpress中不起作用,php,wordpress,email,Php,Wordpress,Email,文本邮件工作正常,但我也想附加文件。 附件不起作用。 我的代码是: <form method="post" enctype="multipart/form-data"> <input name="filepc" type="file" id="filepc" class="listEm" /> </form> if (isset($_POST['submit'])) { $attachments = ''; if (!empty(
<form method="post" enctype="multipart/form-data">
<input name="filepc" type="file" id="filepc" class="listEm" />
</form>
if (isset($_POST['submit'])) {
$attachments = '';
if (!empty($_FILES['filepc']['tmp_name'])) {
$attachments = array($_FILES['filepc']['name']);
}
headers = "From:" . $your_email . " < " . $email . ">" . "\r\n";
$headers .= "Reply - To:" . $ct_email . "\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$attachments."\"\r\n\r\n";
//$headers = "Bcc: someone@domain . com" . "\r\n";
$headers = "X - Mailer: PHP / " . phpversion();
mail($to , $subject , $msg , $headers,$attachments);
$successMsg = '<h5 style="color:red;">Sent successfully</h5>';
// }
}
如果(isset($_POST['submit'])){
$attachments='';
如果(!空($_文件['filepc']['tmp_名称]])){
$attachments=array($_FILES['filepc']['name']);
}
headers=“From:”.$your\u email.“<”$email.>“\r\n”;
$headers.=“回复:”..$ct\U电子邮件。“\r\n”;
$headers.=“内容处置:附件;文件名=\”.$attachments.\“\r\n\r\n”;
//$headers=“密件抄送:someone@domain.com“。\r\n”;
$headers=“X-Mailer:PHP/”.phpversion();
邮件($to、$subject、$msg、$headers、$attachments);
$successsg=‘发送成功’;
// }
}
以上代码有效,但文件未附加。请帮助我找到此问题的解决方案。if(!empty($\u FILES['resume']['name'])){
if(!empty($_FILES['resume']['name'])) {
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$tmp_name = $_FILES['resume']['tmp_name'];
$type = $_FILES['resume']['type'];
$file_name = $_FILES['resume']['name'];
$size = $_FILES['resume']['size'];
// Check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// Now Open the file for a binary read
$file = fopen($tmp_name,'rb');
// Now read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// Now we need to encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
$mybody = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$mybody . "\n\n";
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$mybody .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$bodys .= "$mybody <br>";
$subject = "Attachment";
$body = $body . $bodys;
mail($to, $subject, $body, $headers);
}
$mime_boundary=“==Multipart_boundary_x”.md5(mt_rand())“x”;
$tmp_name=$_文件['resume']['tmp_name'];
$type=$_文件['resume']['type'];
$file\u name=$\u FILES['resume']['name'];
$size=$\u文件['resume']['size'];
//检查以确保它是上载的文件而不是系统文件
如果(是否上载了文件($tmp\U名称)){
//现在打开文件进行二进制读取
$file=fopen($tmp_名称,'rb');
//现在将文件内容读入变量
$data=fread($file,filesize($tmp_name));
//关闭文件
fclose($文件);
//现在我们需要对其进行编码,并将其拆分为可接受的长度行
$data=chunk_split(base64_encode($data));
}
$mybody=“这是MIME格式的多部分消息。\n\n”。
“{$mime\U边界}\n”。
“内容类型:text/html;字符集=\”iso-8859-1\“\n”。
“内容传输编码:7bit\n\n”。
$mybody。“\n\n”;
$headers=“From:$From\r\n”。
“MIME版本:1.0\r\n”。
“内容类型:多部分/混合;\r\n”。
“边界=\”{$mime\u boundary}\”;
$mybody.=“--{$mime\u boundary}\n”。
“内容类型:{$Type};\n”。
“名称=\”{$file\u name}\“\n”。
//“内容处置:附件;\n”。
//“filename=\”{$fileatt\u name}\“\n”。
“内容传输编码:base64\n\n”。
$data。“\n\n”。
“{$mime\u boundary}--\n”;
$body.=“$mybody
”;
$subject=“附件”;
$body=$body.$bodys;
邮件($to、$subject、$body、$headers);
}
$msg=“\n\n”。“电话:$title”。“\n”。“名字:$First_name”。“\n”。“姓氏:$Last_name”。“\n”。“附件:回显‘图像:’;”。“\n”。“首选联系方式:$prmode”。“\n”;如何在带有附件的电子邮件中的邮件中添加此内容如何处理多个附件