我试图触发带有电子邮件附件的表单。但由于某种原因,附件,附件以加密格式提供。请有人帮帮我.... 要求是填写表格和附件,所有细节需要传递到电子邮件ID,没有任何问题......
<?php
if(isset($_POST['submit'])){
// Obtain file upload vars
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$file_name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
$name = trim($_POST['name']);
$age = trim($_POST['age']);
$sex = $_POST['sex'];
$occupation = trim($_POST['occupation']);
$address = trim($_POST['address']);
$email = trim($_POST['email']);
$hphone = trim($_POST['hphone']);
$cphone = trim($_POST['cphone']);
$treatment = trim($_POST['treatment']);
$symptom = trim($_POST['symptom']);
$thistory = trim($_POST['thistory']);
$currmedic = trim($_POST['currmedic']);
$otherprobs = trim($_POST['otherprobs']);
$contactmode = trim($_POST['contactmode']);
$contactinfo = trim($_POST['contactinfo']);
$agree = $_POST['agree'];
$subject = "Request for Consultation from " .$name;
$isError = "N";
if($name == "") {
$nameErrMsg = "Enter your name.";
$nameErr = "1" ;
$isError = "Y";
}
if($age == "") {
$ageErrMsg = "Enter your age.";
$ageErr = "1";
$isError = "Y";
}
if(!isset($sex))
{
$sexErrMsg = "Select your Gender.";
$sexErr = "1";
$isError = "Y";
}
if($address == "") {
$addressErrMsg = "Enter your Address.";
$addressErr = "1";
$isError = "Y";
}
if($email == "") {
$emailErrMsg = "Enter your Email.";
$emailErr = "1";
$isError = "Y";
} //check for valid email
elseif(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
$emailErrMsg = 'You did not enter a valid Email.';
$emailErr = "1";
$isError = "Y";
}
if($cphone == "") {
$cphoneErrMsg = "Enter your Cell Phone.";
$cphoneErr = "1";
$isError = "Y";
}
if($treatment == "") {
$treatmentErrMsg = "Enter your required Treatment.";
$treatmentErr = "1";
$isError = "Y";
}
if($symptom == "") {
$symptomErrMsg = "Enter the Symtoms.";
$symptomErr = "1";
$isError = "Y";
}
if($thistory == "") {
$thistoryErrMsg = "Enter Treatment History.";
$thistoryErr = "1";
$isError = "Y";
}
if($contactinfo == ""){
$contactinfoErrMsg = "Enter Contact Info.";
$contactinfoErr = "1";
$isError = "Y";
}
if(!isset($agree))
{
$agreeErrMsg = "Select for Agree/Disagree to use your medical information in case studies.";
$agreeErr = "1";
$isError = "Y";
}
if($isError == "N")
{
$message = "
Name : $name <br />
Age : $age <br />
Sex : $sex <br />
Occupation : $occupation <br />
Address : $address <br />
Email : $email <br />
Home Phone : $hphone <br />
Cell Phone : $cphone <br />
Treatment For : $treatment <br />
Symptoms : $symptom <br />
Treatment History : $thistory <br />
Current Medications : $currmedic <br />
List out any other associated conditions or health problems that your suffering with : $otherprobs <br />
Preferred mode of Contact : $contactmode <br />
Contact Info : $contactinfo <br />
Agree to use your medical information in case studies : $agree
";
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//$headers = "From: $from\r\n" .
// "MIME-Version: 1.0\r\n" .
// "Content-Type: multipart/mixed;\r\n" .
// " boundary=\"{$mime_boundary}\"";
$message = "\n" .
//"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
//"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= //"--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
"File Name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
//"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" ;
//if (is_uploaded_file($fileatt))
//{
//}
$to = "anand.pikay@gmail.com";
$headers = 'From: '.$email.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'data: '.$data.'' . "\r\n" .
enter code here
'Content-type: text/html; charset=utf-8' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
$send_email = mail($to,$subject,$message,$headers);
if($send_email)
{
$msg= "Your message sent successfully.";
$name = "";
$age = "";
$sex = "";
$occupation = "";
$address = "";
$email = "";
$hphone = "";
$cphone = "";
$treatment = "";
$symptom = "";
$thistory = "";
$currmedic = "";
$otherprobs = "";
$contactmode = "";
$contactinfo = "";
$agree = "";
}
else
{
$errorMsg = "Error in sending email!!!";
}
}
}
?>