Webform工作正常。我只收到电子邮件中的附件名称。它应该将原始文件附加到电子邮件中。有什么帮助吗?
检查以下代码&让我知道如何解决这个问题。
提前致谢。
<?php
if ( isset( $_POST['submit']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$field1=$_POST['field1'];
$field2=$_POST['field2'];
$link=$_POST['link'];
$twit=$_POST['twit'];
$field3=$_POST['field3'];
$field4=$_POST['field4'];
$field5=$_POST['field5'];
$document1=$_FILES['b_plan']['name'];
$document2=$_FILES['presentation']['tmp_name'];
$document3=$_FILES['founder_cvs']['name'];
//echo $title;
//echo $document;
//$path =ABSPATH.'/uploads/applications/'.$_FILES['presentation']['name'];
//$path =ABSPATH.'/uploads/applications/'.$_FILES['b_plan']['name'];
$path =ABSPATH.'/uploads/applications/';
if(isset($_FILES['presentation']['name']))
{
move_uploaded_file($_FILES['presentation']['tmp_name'], $path.$_FILES['presentation']['name']);
}
if(isset($_FILES['founder_cvs']['name']))
{
move_uploaded_file($_FILES['b_plan']['tmp_name'], $path.$_FILES['b_plan']['name']);
}
if(isset($_FILES['founder_cvs']['name']))
{
move_uploaded_file($_FILES['founder_cvs']['tmp_name'], $path.$_FILES['founder_cvs']['name']);
}
//$path =ABSPATH.'wp-content/plugins/document-listing/uploads/'.$_FILES['presentation']['name'];
//wp-content/plugins/document-listing/uploads/
//echo $path;
global $wpdb;
$n = $wpdb->insert(
'wp__form',
array(
'first_name' => $fname,
'last_name' => $lname,
'city' => $city,
'state' => $state,
'country' => $country,
'phone' => $phone,
'email'=>$email,
'gender'=>$gender,
'field1'=>$field1,
'field2'=>$field2,
'link' => $link,
'twit' => $twit,
'field3' => $field3,
'field4' => $field4,
'field5' => $field5,
'b_plan' => $document1,
'presentation' => $document2,
'founder_cvs' =>$document3
)
);
$to= "mehreeen786@gmail.com";
//echo $to; die;
$subject=" application on ";
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['presentation']['tmp_name'])));
$document2 = $_FILES['presentation']['name'];
$body = "
<p>Dear Admin</p>
<p>An application has been received. Please find below the details:</p>
Title: ".$title."<br/>
First Name: ".$fname."<br/>
Last Name: ".$lname."<br/>
City: ".$city."<br/>
Emirate/Province: ".$state."<br/>
Country: ".$country."<br/>
Phone Number: ".$phone."<br/>
Email: ".$email."<br/>
Gender: ".$gender."<br/>
How did you hear about ?: ".$field1."<br/>
Company Name: ".$fields2."<br/>
Management Team (short bios with names, educations, and experience): ".$field3."<br/>
LinkedIn: ".$link."<br/>
Twitter: ".$twit."<br/>
Executive Summary : ".$field4."<br/>
Anything else you want to add? : ".$field5."<br/>
Founder CV: ".$document3."<br/>
Presentation Deck: ".$document2."<br/>
Financial Projections: ".$document1."<br/>
<p>Thanks </p>
<p> Team </p> ";
$headers = 'From: '.$email.''. "\r\n" .
'Reply-To: '.$email."\r\n".
'MIME-Version: 1.0' . "\r\n".
'Content-type: text/html; charset=iso-8859-1';
if(mail($to,$subject,$body,$headers))
{
header('Location:/thankyou/');
}
}
//echo $msg;
?>
答案 0 :(得分:0)
看起来您实际上没有在电子邮件中附加任何内容。您定义$attachment
,但永远不会在任何地方使用。我建议使用类似PHPMailer之类的东西来简化这一过程。一旦你导入PHPMailer,附加东西很简单:
$email = new PHPMailer();
$email->From = 'you@example.com';
$email->FromName = 'Your Name';
$email->Subject = $subject;
$email->Body = $body;
$email->AddAddress( $to );
$email->AddAttachment( $path . $document2 , $document2 );
$email->Send();