php邮件附件在wordpress中失败

php邮件附件在wordpress中失败,wordpress,attachment,php,Wordpress,Attachment,Php,我正在使用wordpress创建我的网站。有人能帮我找出为什么php邮件附件无法从我的wordpress文件夹以外的其他位置附加文件吗??? 这是我的密码: $subject="Enquiry"; $to = "veena@phenomtec.com"; $from = $_POST['email']; $url=$_POST['resume']; $attachment = chunk_split(base64_encode(file_get_contents($url))); $filen

我正在使用wordpress创建我的网站。有人能帮我找出为什么php邮件附件无法从我的wordpress文件夹以外的其他位置附加文件吗??? 这是我的密码:

$subject="Enquiry";
$to = "veena@phenomtec.com";
$from = $_POST['email'];
$url=$_POST['resume']; 
$attachment = chunk_split(base64_encode(file_get_contents($url)));
$filename = basename($url);
$parts=explode("?",$filename);
$filename = $parts[0]; 

    $boundary =md5(date('r', time())); 
    $headers = "From: $from\r\nReply-To: $from";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
    $message="This is a multi-part message in MIME format.
    --_1_$boundary
     Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

    --_2_$boundary
Content-Type: text/html; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment
--_1_$boundary--";


if ( mail($to, $subject, $message, $headers) ){

    echo "<script>alert('Your email message successfully sent.')</script>";
}
else{

 echo "<script>alert('Sorry, message delivery failed. Contact webmaster for more info.')</script>";
 }
$subject=“查询”;
$to=”veena@phenomtec.com";
$from=$_POST['email'];
$url=$_POST['resume'];
$attachment=chunk\u split(base64\u编码(文件获取内容($url));
$filename=basename($url);
$parts=分解(“?”,$filename);
$filename=$parts[0];
$boundary=md5(日期('r',时间());
$headers=“From:$From\r\n提交至:$From”;
$headers.=“\r\n时间版本:1.0\r\n内容类型:多部分/混合;边界=\”\u 1\u$boundary\”;
$message=“这是MIME格式的多部分消息。
--_1美元边界
内容类型:多部分/可选;边界=\“\u 2\u$boundary\”
--_2美元边界
内容类型:text/html;字符集=\“iso-8859-1”
内容传输编码:7bit
$message
--_2美元边界--
--_1美元边界
内容类型:应用程序/八位字节流;名称=\“$filename\”
内容传输编码:base64
内容配置:附件
$attachment
--_1_u$边界--“;
if(邮件($to、$subject、$message、$headers)){
回显“警报('您的电子邮件已成功发送')”;
}
否则{
echo“警报('抱歉,邮件传递失败。有关详细信息,请与网站管理员联系')”;
}
我可以从wordpress文件夹中附加文件。但我无法附加其他位置的文件。有人请帮帮我。
提前感谢。

首先确保您的表单中有enctype=“multipart/form data”:

<form method="post" enctype="multipart/form-data">

然后尝试以下代码:

$subject="Enquiry";
$to = "veena@phenomtec.com";
$from = $_POST['email'];
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['resume']['tmp_name'])));
    $filename = $_FILES['resume']['name'];

    $boundary =md5(date('r', time())); 

    $headers = "From: $from\r\nReply-To: $from";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

--_2_$boundary
Content-Type: text/html; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment
--_1_$boundary--";


if ( mail($to, $subject, $message, $headers) ){

    echo "<script>alert('Your email message successfully sent.')</script>";
}
else{

 echo "<script>alert('Sorry, message delivery failed. Contact webmaster for more info.')</script>";
 }
$subject=“查询”;
$to=”veena@phenomtec.com";
$from=$_POST['email'];
$attachment=chunk\u split(base64\u编码(文件获取内容($\u文件['resume']['tmp\u name']));
$filename=$_文件['resume']['name'];
$boundary=md5(日期('r',时间());
$headers=“From:$From\r\n提交至:$From”;
$headers.=“\r\n时间版本:1.0\r\n内容类型:多部分/混合;边界=\”\u 1\u$boundary\”;
$message=“这是MIME格式的多部分消息。
--_1美元边界
内容类型:多部分/可选;边界=\“\u 2\u$boundary\”
--_2美元边界
内容类型:text/html;字符集=\“iso-8859-1”
内容传输编码:7bit
$message
--_2美元边界--
--_1美元边界
内容类型:应用程序/八位字节流;名称=\“$filename\”
内容传输编码:base64
内容配置:附件
$attachment
--_1_u$边界--“;
if(邮件($to、$subject、$message、$headers)){
回显“警报('您的电子邮件已成功发送')”;
}
否则{
echo“警报('抱歉,邮件传递失败。有关详细信息,请与网站管理员联系')”;
}

希望这能奏效:)

只是一个猜测,但要确保
$url
是一个绝对url,而不是相对url。