Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ini_set('display_errors', 1);
- // ini_set('display_startup_errors', 1);
- // error_reporting(E_ALL);
- /**
- * This example shows settings to use when sending via Google's Gmail servers.
- * This uses traditional id & password authentication - look at the gmail_xoauth.phps
- * example to see how to use XOAUTH2.
- * The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
- */
- //Import PHPMailer classes into the global namespace
- use PHPMailer\PHPMailer\PHPMailer;
- require '../../vendor/autoload.php';
- $employeeName = "";
- $employeeEmail = "";
- $employeeRecommendation = "";
- $friendsName = "";
- $friendsEmail = "";
- $friendsPhone = "";
- //get properties from form
- if (isset($_POST['name'])) {
- $employeeName = $_POST['name'];
- }
- if (isset($_POST['email'])) {
- $employeeEmail = $_POST['email'];
- }
- if (isset($_POST['recommendation'])) {
- $employeeRecommendation = $_POST['recommendation'];
- }
- if (isset($_POST['friends_name'])) {
- $friendsName = $_POST['friends_name'];
- }
- if (isset($_POST['friends_email'])) {
- $friendsEmail = $_POST['friends_email'];
- }
- if (isset($_POST['friends_phone'])) {
- $friendsPhone = $_POST['friends_phone'];
- }
- if ($employeeRecommendation == "") {
- echo "recommendation badly formed";
- die();
- if (preg_match('/[^A-Za-ząčęėįšųūžĄČĘĖĮŠŲŪŽ]/', $employeeName)) {
- echo "recommendation badly formed";
- header('Location: formController.php');
- die();
- }
- }
- if (preg_match("/^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð ,.'-]+$/u", $employeeName)) { //check if name is text only
- if (filter_var($employeeEmail, FILTER_VALIDATE_EMAIL)) { //check if email is valid
- if (preg_match("/^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð ,.'-]+$/u", $employeeName)) { //check if name is text only
- if (filter_var($employeeEmail, FILTER_VALIDATE_EMAIL)) { // if email is valid
- if (strpos($friendsPhone, '+') !== false) { // check if valid phone
- if ($_FILES["fileToUpload"]["name"] != "") { //check if file is set
- $target_dir = "../../uploads/";
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- $fileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
- if ($fileType != "doc" && $fileType != "pdf" && $fileType != "odt" && $fileType != "docx") {
- echo "Sorry only doc pdf and odt file types accepted.";
- header('Location: formController.php');
- die();
- }
- if ($_FILES["fileToUpload"]["size"] > 500000) {
- echo "Sorry, your file is too large.";
- header('Location: formController.php');
- die();
- }
- }
- //dar reik patikrint ar zjbs failas
- $emailText = array( //čia kad tekstą patogiau formuot jei ką persiduot kitam failui
- 'employee_name' => $employeeName,
- 'employee_email' => $employeeEmail,
- 'recommendation' => $employeeRecommendation,
- 'friends_name' => $friendsName,
- 'friends_email' => $friendsEmail,
- 'friends_phone' => $friendsPhone,
- );
- // if('viskas zjbs') siųsti email
- $mail = new PHPMailer;
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- $mail->isHTML();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 0;
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // if your network does not support SMTP over IPv6
- //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
- $mail->Port = 587;
- //Set the encryption system to use - ssl (deprecated) or tls
- $mail->SMTPSecure = 'tls';
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication - use full email address for gmail
- $mail->Username = "formsteltonika@gmail.com";
- //Password to use for SMTP authentication
- $mail->Password = "2018KaunasTeltonika?";
- //Set who the message is to be sent from
- $mail->setFrom('formsteltonika@gmail.com', 'Darbuotojo rekomendacija');
- //Set an alternative reply-to address
- $mail->addReplyTo('formsteltonika@gmail.com', 'Darbuotojo rekomendacija');
- //Set who the message is to be sent to
- $mail->addAddress('kestas3210@gmail.com', 'Čia hr vardas');
- $mail->Subject = $employeeName . ' ' . 'jums rekomenduoja darbuotoją';
- //Replace the plain text body with one created manually
- //$varasdasd = include("/var/www/html/recommend-form/app/views/emailContent.html");
- $mail->Body = formEmail($employeeName, $employeeEmail, $friendsName, $friendsEmail, $friendsPhone, $employeeRecommendation);
- //Attach cv image file
- if ($_FILES["fileToUpload"]["name"] != "") {
- $mail->AddAttachment($_FILES['fileToUpload']['tmp_name'],
- $_FILES['fileToUpload']['name']);
- }
- $mail->CharSet = 'UTF-8';
- if ($mail->send()) {
- $logMessege = date("Y-m-d H:i:s")."|".$emailText["employee_name"] . "|" . $emailText["employee_email"] . "|" . $emailText["recommendation"] . "|" . $emailText["friends_name"] . "|" . $emailText["friends_email"] . "|" . $emailText["friends_phone"];
- logToFile($logMessege);
- ?>
- <script>window.location = "formController.php"</script>
- // header('Location: formController.php');<?php
- die();
- //Section 2: IMAP
- //Uncomment these to save your message in the 'Sent Mail' folder.
- #if (save_mail($mail)) {
- # echo "Message saved!";
- #}
- } else {
- // mailer errors
- echo "Mailer Error: " . $mail->ErrorInfo;
- }
- } else {
- echo 'Blogai įvestas draugo numeris';
- header('Location: formController.php');
- die();
- }
- } else {
- echo 'Blogai įvestas draugo email';
- header('Location: formController.php');
- die();
- }
- } else {
- 'Blogai įvestas draugo vardas';
- header('Location: formController.php');
- die();
- }
- } else {
- echo 'Blogai įvestas tavo email';
- header('Location: formController.php');
- die();
- }
- } else {
- echo 'Blogai įvesti duomenys';
- header('Location: formController.php');
- die();
- }
- //Create a new PHPMailer instance
- //Section 2: IMAP
- //IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
- //Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
- //You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
- //be useful if you are trying to get this working on a non-Gmail IMAP server.
- function save_mail($mail)
- {
- //You can change 'Sent Mail' to any other folder or tag
- $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
- //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
- $imapStream = imap_open($path, $mail->Username, $mail->Password);
- $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
- imap_close($imapStream);
- return $result;
- }
- function logToFile($messege)
- {
- $f = fopen("../../log.txt", "a+");
- fwrite($f, $messege . "\n");
- fclose($f);
- }
- function formEmail($employeeName, $employeeEmail, $friendsName, $friendsEmail, $friendsPhone, $employeeRecommendation)
- {
- $filename = "../views/emailContent1.html";
- $handle = fopen($filename, "r");
- $contents = fread($handle, filesize($filename));
- fclose($handle);
- $recommendation = "Sveiki, " . $employeeName . " (" . $employeeEmail . ")" . " jums rekomenduoja naują darbuotoją:" .
- $friendsName . " " . $friendsEmail . " " . $friendsPhone . "." . " " . $employeeName . " mano, kad" . $friendsName . "yra tinkamas, nes:" .
- $employeeRecommendation;
- $filename = "../views/emailContent2.html";
- $handle = fopen($filename, "r");
- $contents1 = fread($handle, filesize($filename));
- fclose($handle);
- $recommendationEmail = $contents . $recommendation . $contents1;
- return $recommendationEmail;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement