Mails send separatly. Input text used.
Res T123,T124
This commit is contained in:
parent
199a89a8d4
commit
a3c02b057d
8 changed files with 129 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ assets/
|
||||||
templates/
|
templates/
|
||||||
lists/
|
lists/
|
||||||
vendor/
|
vendor/
|
||||||
|
*~
|
||||||
|
|
10
README.md
10
README.md
|
@ -24,6 +24,16 @@ gulp sass
|
||||||
gulp coffee
|
gulp coffee
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Make sure you have dart installed on your system and run
|
||||||
|
|
||||||
|
```
|
||||||
|
cd res/dart/
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
dart2js -m -o main.js main.dart
|
||||||
|
```
|
||||||
|
|
||||||
Create the folders `templates`, `assets` and `lists` and make sure that the server can write in these folders.
|
Create the folders `templates`, `assets` and `lists` and make sure that the server can write in these folders.
|
||||||
|
|
||||||
Finally remove the example files.
|
Finally remove the example files.
|
||||||
|
|
|
@ -10,3 +10,6 @@ timezone = "UTC"
|
||||||
email = "example@example.com"
|
email = "example@example.com"
|
||||||
; name which is given as a sender name
|
; name which is given as a sender name
|
||||||
name = "John"
|
name = "John"
|
||||||
|
; reply address
|
||||||
|
; if not set, the values above will be used
|
||||||
|
reply = ""
|
|
@ -171,5 +171,6 @@
|
||||||
|
|
||||||
<script src="./res/js/jquery-2.1.4.min.js"></script>
|
<script src="./res/js/jquery-2.1.4.min.js"></script>
|
||||||
<script src="./res/js/main.js"></script>
|
<script src="./res/js/main.js"></script>
|
||||||
|
<script src="./res/dart/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
23
res/dart/.gitignore
vendored
Normal file
23
res/dart/.gitignore
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Files and directories created by pub
|
||||||
|
.packages
|
||||||
|
.pub/
|
||||||
|
build/
|
||||||
|
packages
|
||||||
|
# Remove the following pattern if you wish to check in your lock file
|
||||||
|
pubspec.lock
|
||||||
|
|
||||||
|
# Files created by dart2js
|
||||||
|
*.dart.js
|
||||||
|
*.part.js
|
||||||
|
*.js.deps
|
||||||
|
*.js.map
|
||||||
|
*.info.json
|
||||||
|
|
||||||
|
# Directory created by dartdoc
|
||||||
|
doc/api/
|
||||||
|
|
||||||
|
# JetBrains IDEs
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
34
res/dart/main.dart
Normal file
34
res/dart/main.dart
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (c) 2016, Marcel Kapfer (mmk2410).
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:html';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// send mail listener
|
||||||
|
querySelector("#send").onClick.listen(sendMail);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMail(MouseEvent event) {
|
||||||
|
InputElement title = querySelector("#mailtitle");
|
||||||
|
InputElement text = querySelector("#mailtext");
|
||||||
|
InputElement filename = querySelector("#filename");
|
||||||
|
InputElement addresslist = querySelector("#address_list");
|
||||||
|
|
||||||
|
Map data = {
|
||||||
|
"title": title.value,
|
||||||
|
"body": text.value,
|
||||||
|
"filename": filename.value,
|
||||||
|
"list": addresslist.value
|
||||||
|
};
|
||||||
|
|
||||||
|
String url = "/res/php/sendmail.php?data=${JSON.encode(data)}";
|
||||||
|
|
||||||
|
HttpRequest.getString(url).then((response) {
|
||||||
|
if (response == "0") {
|
||||||
|
window.alert("Mails successfully sent.");
|
||||||
|
} else {
|
||||||
|
window.alert("Failed to send mail.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -3,8 +3,21 @@
|
||||||
# MIT License
|
# MIT License
|
||||||
|
|
||||||
main = ->
|
main = ->
|
||||||
|
###
|
||||||
$("#send").click ->
|
$("#send").click ->
|
||||||
|
url = "/res/php/sendmail.php"
|
||||||
|
data = new FormData
|
||||||
|
data.append "json", JSON.stringify
|
||||||
|
a: 1
|
||||||
|
b: "test"
|
||||||
|
request = new Request url,
|
||||||
|
method: 'POST'
|
||||||
|
body: data
|
||||||
|
fetch request
|
||||||
|
.then (response) ->
|
||||||
|
console.log response
|
||||||
|
###
|
||||||
|
###
|
||||||
url = "./res/php/sendmail.php?list=" + $("#address_list").val() +
|
url = "./res/php/sendmail.php?list=" + $("#address_list").val() +
|
||||||
"&template=" + $("#templates_list").val()
|
"&template=" + $("#templates_list").val()
|
||||||
$.get url, (data) ->
|
$.get url, (data) ->
|
||||||
|
@ -12,6 +25,7 @@ main = ->
|
||||||
alert "Mail sent!"
|
alert "Mail sent!"
|
||||||
else
|
else
|
||||||
alert "Sending mail failed!"
|
alert "Sending mail failed!"
|
||||||
|
###
|
||||||
|
|
||||||
updateAddressLists()
|
updateAddressLists()
|
||||||
|
|
||||||
|
|
|
@ -8,46 +8,52 @@ date_default_timezone_set($ini["timezone"]);
|
||||||
|
|
||||||
require '../../vendor/autoload.php';
|
require '../../vendor/autoload.php';
|
||||||
|
|
||||||
$list = "../../lists/" . $_GET["list"];
|
function main($ini) {
|
||||||
$template = "../../templates/" . $_GET["template"];
|
|
||||||
|
|
||||||
$addresses = file($list);
|
$data = json_decode($_GET["data"], true);
|
||||||
$content = file($template);
|
|
||||||
|
|
||||||
$email = new PHPMailer;
|
$list = "../../lists/" . $data["list"];
|
||||||
|
$addresses = file($list);
|
||||||
|
|
||||||
$email->setFrom($ini["email"], $ini["name"]);
|
$content = $data["body"];
|
||||||
$email->Subject = parseSubject($content);
|
|
||||||
$email->Body = parseText($content);
|
|
||||||
|
|
||||||
foreach ($addresses as $address) {
|
$title = $data["title"];
|
||||||
$email->AddAddress($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
$file_to_attach = '../../assets/file.bin';
|
$filename = $data["filename"];
|
||||||
$filename = parseFilename($content);
|
|
||||||
|
|
||||||
$email->AddAttachment($file_to_attach, $filename);
|
foreach ($addresses as $address) {
|
||||||
|
if (sendMail($title, $content, $filename, $address, $ini) != 0) {
|
||||||
if (!$email->Send()) {
|
print "-1";
|
||||||
echo "-1";
|
exit;
|
||||||
echo $email->ErrorInfo;
|
|
||||||
} else {
|
|
||||||
echo "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseSubject($content) {
|
|
||||||
return substr($content[0], 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseFilename($content) {
|
|
||||||
return substr($content[1], 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseText($content) {
|
|
||||||
$text = substr($content[2], 6);
|
|
||||||
for ($i = 3; $i < count($content); $i++) {
|
|
||||||
$text = $text . $content[$i];
|
|
||||||
}
|
}
|
||||||
return $text;
|
}
|
||||||
|
|
||||||
|
print "0";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendMail($title, $content, $filename, $address, $ini) {
|
||||||
|
|
||||||
|
$mail = new PHPMailer;
|
||||||
|
|
||||||
|
$mail->setFrom($ini["email"], $ini["name"]);
|
||||||
|
$mail->Subject = $title;
|
||||||
|
$mail->Body = $content;
|
||||||
|
|
||||||
|
$mail->addAddress($address);
|
||||||
|
|
||||||
|
if (isset($ini["reply"])) {
|
||||||
|
$mail->addReplyTo($ini["reply"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail->AddAttachment("../../assets/file.bin", $filename);
|
||||||
|
|
||||||
|
if (!$mail->Send()) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main($ini);
|
||||||
|
|
Reference in a new issue