forked from agrogeophy/catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification_handler_OV.php
91 lines (70 loc) · 2.54 KB
/
notification_handler_OV.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
// echo 'email';
// echo '<br>';
// echo 'file count=', count($_FILES),"\n";
// var_dump($_FILES);
// echo '<br>';
// ------------------------------------------------------------------------------------
// VALUES TO REPLACE
require("PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "smtp.??.??";
$mail->Port = "25";
$mail->SMTPAuth = false;
$mail->From = "??";
$mail->FromName = "??";
$mail->AddAddress( "??","Admin catalog");
$mail->Subject = "Notification new contribution - User: ".$_POST["name"] . "','" . $_POST["surname"] . "','" . $_POST["organisation"];
$email_message = "New contribution to add into the db from:\n\n";
$email_message .= "User: ".$_POST["name"] . "','" . $_POST["surname"] . "','" . $_POST["organisation"]."\n\n";
//Encode the array into a JSON string.
$arr = $_POST;
// echo var_dump($_FILES);
echo "<br>";
$arr['icon_img']= $_FILES['keyFigure']['name'];
// echo var_dump($arr);
$arr['notebook_file']= $_FILES['notebook_file']['name'];
// echo var_dump($arr);
$encodedString = json_encode($arr);
// echo $encodedString;
date_default_timezone_set('France/Paris');
$date = date('Y-m-d H:i:s');
$jsonname= 'json_array_'. $_POST["name"] . "_" . $_POST["surname"] . "_" . $date.'.txt';
//Save the JSON string to a text file.
file_put_contents($jsonname, $encodedString);
$mail->addStringAttachment($encodedString, $jsonname);
function AddAttachment($path,
$name = '',
$encoding = 'base64',
$type = 'application/octet-stream')
{
}
if (isset($_FILES['keyFigure']) &&
$_FILES['keyFigure']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['keyFigure']['tmp_name'],
$_FILES['keyFigure']['name']);
}
// echo isset($_FILES['notebook_file'];
// echo $_FILES['notebook_file']['error'] == UPLOAD_ERR_OK;
if (isset($_FILES['notebook_file']) &&
$_FILES['notebook_file']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['notebook_file']['tmp_name'],
$_FILES['notebook_file']['name']);
}
// https://thisinterestsme.com/saving-php-array-text-file/
$email_message .= $encodedString;
$mail->Body = $email_message;
$mail->WordWrap = 120;
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' .$mail->ErrorInfo;
exit;
}
else
{
echo '<div> E-mail sent to Agrogeophysical Catalog Admin, we will get back to you very soon! Thanks for your contribution <div>';
}
?>