-
Notifications
You must be signed in to change notification settings - Fork 0
/
applicationform.php
73 lines (56 loc) · 2.38 KB
/
applicationform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
if($_POST && isset($_FILES['file1']))
{
$from_email = '[email protected]'; //sender email
$to = '[email protected]'; //recipient email
$subject = 'New Application'; //subject of email
$message = 'Required Information:'; //message body
$name = $_POST['name'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$team = $_POST['team'];
$interest = $_POST['interest'];
//get file details we need
$file_tmp_name = $_FILES['file1']['tmp_name'];
$file_name = $_FILES['file1']['name'];
$file_size = $_FILES['file1']['size'];
$file_type = $_FILES['file1']['type'];
$file_error = $_FILES['file1']['error'];
$user_email = filter_var($_POST["mail"], FILTER_SANITIZE_EMAIL);
if($file_error>0)
{
die('upload error');
}
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("sanwebe");
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$user_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode("Email: " . $mail . "\r\n " . "Name: " . $name . "\r\n" . "Phone: " . $phone . "\r\n" . "District: " . $team . "\r\n" . "Interest: " . $interest));
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
//other
$sentMail = @mail($to, $subject, $body, $headers);
if($sentMail) //output success or failure messages
{
die('Thank you for your application!');
}else{
die('Could not send mail! Please check your PHP mail configuration.');
}
}
?>