PHP邮件附件在wordpress中失败



我使用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: $fromrnReply-To: $from";
    $headers .= "rnMIME-Version: 1.0rnContent-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>";
 }

我能够从我的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: $fromrnReply-To: $from";
    $headers .= "rnMIME-Version: 1.0rnContent-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>";
 }

希望这将工作:)

相关内容

  • 没有找到相关文章

最新更新