-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattach-ec.php
70 lines (56 loc) · 2.23 KB
/
attach-ec.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
<?php
session_start();
//recipient
$to = '[email protected]';
//sender
$sender = $_SESSION['email'];
$senderName = $_SESSION['name'];
//email subject
$subject = 'New Domestic Shipping Order';
//attachment file path
$file = "data\EC-quote.txt";
//email body content
$htmlContent = '<h1>Domestic Shipping Quote Request</h1>
<p>
Hi. Please find attached my details for a Domestic Shipment.
I await your response with an invoice.
Thank you.
</p>';
//header for sender info
$headers = "From: $senderName"." <".$sender.">";
//boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
//multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
//preparing attachment
if(!empty($file) > 0){
if(is_file($file)){
$message .= "--{$mime_boundary}\n";
$fp = @fopen($file,"rb");
$data = @fread($fp,filesize($file));
@fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
"Content-Description: ".basename($file)."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $sender;
//send email
$mail = @mail($to, $subject, $message, $headers, $returnpath);
//email sending status
// echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1>";
if ($mail) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=quote-ec-success.php\">";
}
else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=quote-ec-error.html\">";
// die("Sorry but the email could not be sent. Please go back and try again!");
}
?>