Jump to content

rizwanullahtahir

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by rizwanullahtahir

  1. i have wrote following code for send email with attachment but it is not working. Please review it and tell me the problem in code. <?php // request variables // important $from = $_REQUEST["from"]; $emaila = $_REQUEST["emaila"]; $filea = $_REQUEST["filea"]; $to = "rizwanullahtahir@gmail.com"; $candidatename = $_POST['candidate-name']; $guardianname = $_POST['guardian-name']; $relationwithguardian = $_POST['relation-with-guardian']; $candidateemail = $_POST['candidate-email']; $guardianemail = $_POST['guardian-email']; $dateofbirth = $_POST['birthday']; $ageofCandidate = $_POST['Age']; $candidatesex = $_POST['sex']; $phone = $_POST['phone']; $skypeusername = $_POST['skype-username']; $whatsapp = $_POST['Whatsapp-username']; $permanentaddress = $_POST['permanent-address']; $mailingaddress = $_POST['mailing-address']; $country = $_POST['country']; $timezone = $_POST['timezone_offset']; $stateprovince = $_POST['State/Province']; $city = $_POST['City']; $zipcode = $_POST['zip-code']; $moftech = $_POST['Medium-Of-Teaching']; $classenroll = $_POST['Class-Enrollment']; $paymentmethod = $_POST['Payment-Method']; $fileattachment = $_FILES['attachment']['name']; $admitdate = $_POST['Admission-Form-Submission-Date']; if ($filea) { function mail_attachment ($email_from , $to, $subject, $message, $attachment){ $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start = strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $email_from = $from . '$emaila'; // Who the email is from $subject = "New Applicant Documents"; $email_subject = $subject; // The Subject of the email $email_txt = $message; // Message that the email has in it $email_to = $to; // Who the email is to $headers = "From: . '$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $msg_txt='\n\n You have recieved a new attachment message from $from' . '\n\n Candidate Name: . $candidatename <br/>' . '\n\n Guardian Name: . $guardianname<br/>' . '\n\n Relation With Candidate: . $relationwithguardian<br/>' . '\n\n Candidate Email: . $candidateemail <br/>' . '\n\n Guardian Email: . $guardianemail<br/>' . '\n\n Date of Birth: . $dateofbirth <br/>' . '\n\n Candidate Age At the Time of Admisssion: . $ageofCandidate<br/>' . '\n\n Candidate Sex: . $candidatesex<br/>' . '\n\n Phone: . $phone <br/>' . '\n\n Skype Username: . $skypeusername <br/>' . ' '\n\n Whatsapp: . $whatsapp <br/>' . '\n\n Permanent Address: . $permanentaddress<br/>' . '\n\n Mailing Address: . $mailingaddress<br/>' . '\n\n Country: . $country<br/>' . '\n\n State/Province: . $stateprovince<br/>' . '\n\n City: . $city<br/>' . '\n\n Time-Zone: . $timezone<br/>' . '\n\n Zip Code: . $zipcode<br/>' . '\n\n Medium Of Teaching: . $moftech<br/>' . ' \n\n Class Inwhich Want to Enroll: . $classenroll<br/>' . '\n\n Payment Method: . $paymentmethod<br/>' . '\n\n Date Of Application submission: . $admitdate <br/>' $semi_rand = md5(time()); $mime_boundary = '==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_txt = "$msg_txt"; $email_message = "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" . $email_txt . "\n\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . ' name = \"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename = \"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n'; $ok = mail($email_to, $email_subject, $email_message, $headers); if($ok) { echo "File Sent Successfully."; unlink($attachment); // delete a file after attachment sent. }else { die("Sorry but the email could not be sent. Please go back and try again!"); } } move_uploaded_file($_FILES["filea"]["tmp_name"], 'temp/'.basename($_FILES['filea']['name'])); mail_attachment("$from", "$to", "$subject", "$message", ("temp/".$_FILES["filea"]["name"])); } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.