Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $formid = 'fomid-'. $module->autoid() . '_';
- //PHPmailer
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require_once __DIR__ . '/phpmailer/vendor/phpmailer/phpmailer/src/Exception.php';
- require_once __DIR__ . '/phpmailer/vendor/phpmailer/phpmailer/src/PHPMailer.php';
- require_once __DIR__ . '/phpmailer/vendor/phpmailer/phpmailer/src/SMTP.php';
- ?>
- <form action="<?php $module->action(); ?>" method="<?php echo $module->method(); ?>" enctype="<?php e($module->enctype() == 'multipart', 'multipart/form-data'); ?>" class="<?php echo $module->modulclass(); ?>" style="<?php echo $module->fieldstyle(); ?>">
- <?php echo $module->modules(['formid' => $formid]); ?>
- <input type="hidden" name="csrf" value="<?php echo csrf(); ?>">
- </form>
- <?php
- if(r::is('post') && get($formid . 'submit')) {
- $token = $_POST['csrf'];
- if(csrf($token) === true) {
- $formItems = $_POST; //Fill var with the $_POST
- array_splice($formItems, -2); //delete CSFR and submit
- //get Data for Mailtext
- $formItemsHTML = '';
- $formItemsNoHTML = '';
- if(isset($formItems['Sonstiges-20'])){
- $sonstiges = $formItems['Sonstiges-20']; //save sonstiges form in var
- unset($formItems['Sonstiges-20']); // delete sonstiges from array
- }
- foreach($formItems as $key => $value){
- $origkey = $key;
- if($key == 'Sonstiges-20') {
- unset($key['Sonstiges-20']);
- }
- if($key !== 'Nutzung_(aktuell)' AND $key !== 'Bebauung_(aktuell)'){
- $key = strstr($key, '-', true);
- $key = ucwords($key);
- }
- $key = str_replace('_', ' ', $key);
- // $searchWord = ['as', 'or', 'of', 'by'];
- // $key = str_ireplace($searchWord, $searchWord, $key);
- // $searchUCWordOne = ['ssp', 'ape', 'vat', 'po '];
- // $searchUCWordTwo = ['SSP', 'APE', 'VAT', 'PO '];
- // $key = str_ireplace($searchUCWordOne, $searchUCWordTwo, $key);
- // $searchWord = ['conference', 'organisation', 'adress'];
- // $searchUCWord = ['Conference', 'Organisation', 'Adress'];
- // $key = str_ireplace($searchWord, $searchUCWord, $key);
- if($value == 'Sonstiges' AND isset($sonstiges)){
- $value = $sonstiges;
- }
- if ($value === 'on'):
- $value = '✓';
- // $searchWord = ['on'];
- // $replace = ['✓'];
- // $value = str_ireplace($searchWord, $replace, $value);
- elseif(empty($value)):
- $value = '-';
- endif;
- $plainValue = $value;
- $formItemsHTML .= '
- <tr>
- <td width="230" style="padding-left: 15px; padding-top:5px; padding-bottom:5px;"><b>' . $key . '</b></td>
- <td width="270" style="padding-right: 10px; padding-top:5px; padding-bottom:5px;">' . $plainValue .'</td>
- </tr>';
- $formItemsNoHTML .= $key . $plainValue;
- }
- $headerHTMLOne = file_get_contents(__DIR__ . '/htmlmail-header-one.html');
- $headerHTMLTwo = file_get_contents(__DIR__ . '/htmlmail-header-two.html');
- $footerHTML = file_get_contents(__DIR__ . '/htmlmail-footer.html');
- $bodyHTMLOne = $headerHTMLOne . $formItemsHTML . $footerHTML;
- $bodyHTMLTwo = $headerHTMLTwo . $formItemsHTML . $footerHTML;
- $bodyNoHTML = $formItemsNoHTML;
- $mail = new PHPMailer(true);
- $maximumfiles = 10;
- $finfo = new finfo;
- $acceptedMime = ['jpg' => 'image/jpeg','png' => 'image/png','gif' => 'image/gif','pdf' => 'application/pdf'];
- // $mail->isSMTP();
- $mail->IsSendmail();
- $mail->SMTPAuth = true;
- $mail->Host = $site->smtphost();
- $mail->Username = $site->smtpusername();
- $mail->Password = $site->smtppassword();
- $mail->Port = $site->smtpport();
- $mail->SMTPSecure = 'tls';
- $mail->SMTPDebug = 1;
- $from_name = '';
- $from_nameTwo = $site->mainmailname();
- $from_mail = '';
- $from_mailTwo = $site->mainmail();
- $replyto = 'XYZ@gmail.com';
- $replytoTwo = $site->mainmail();
- $mailto = $site->mainmail();
- $mailtoTwo = 'XYZ@gmail.com';
- $subject = $page->title();
- $messageHTML = $bodyHTML;
- $messageNoHTML = $bodyNoHTML;
- // 1.mail – Mail to the websiteoperator
- $mail->CharSet = "UTF-8";
- $mail->From = $from_mail;
- $mail->FromName = $from_name;
- $mail->addAddress($mailto); // Add a "To" address
- $mail->addReplyTo($replyto); // Antwortadresse festlegen
- $mail->isHTML(true); // Mail als HTML versenden
- try {
- if (array_key_exists('uploaded_files', $_FILES)) {
- //Attach multiple files one by one
- for ($i = 0; $i < count($_FILES['uploaded_files']['tmp_name']); $i++) {
- if ($i == $maximumfiles) {
- throw new RuntimeException('<div class="alert">Sie haben zuviele Dateien hochgeladen.</div>');
- }
- if (!isset($_FILES['uploaded_files']['error'][$i])) {
- throw new RuntimeException('<div class="alert">Etwas mit Ihren Dateien stimmt nicht.</div>');
- }
- switch ($_FILES['uploaded_files']['error'][$i]) {
- case UPLOAD_ERR_OK:
- break;
- // case UPLOAD_ERR_NO_FILE:
- // throw new RuntimeException('<div class="alert">Eine Ihrer Dateien scheint nicht verschickt worden zu sein.</div>');
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- throw new RuntimeException('<div class="alert">Eine Ihrer Dateien scheint von der Datenmenge groß zu sein.</div>');
- // default:
- // throw new RuntimeException('<div class="alert">Ein unbekannter Fehler ist aufgetreten.</div>');
- }
- if ($_FILES['uploaded_files']['size'][$i] > 5000000) {
- throw new RuntimeException('<div class="alert">Die maximale Dateigröße ist überschritten.</div>');
- }
- // if(in_array($finfo->file($_FILES['uploaded_files']['tmp_name'][$i]), $acceptedMime, true) === false){
- // throw new RuntimeException('<div class="alert">Invalid file format.</div>');
- // }
- // if (false === $ext = array_search(
- // $finfo->file($_FILES['uploaded_files']['tmp_name'][$i]),
- // array(
- // 'jpg' => 'image/jpeg',
- // 'png' => 'image/png',
- // 'gif' => 'image/gif',
- // 'pdf' => 'application/pdf',
- // ),
- // true
- // )) {
- // throw new RuntimeException('<div class="alert">Invalid file format.</div>');
- // }
- $uploadfile = $_FILES['uploaded_files']['tmp_name'][$i];
- $filename = $_FILES['uploaded_files']['name'][$i];
- $files = $mail->addAttachment($uploadfile, $filename);
- }
- }
- $mail->Subject = $subject;
- $mail->Body = $messageHTML;
- $mail->AltBody = $messageNoHTML;
- if(isset($uploadfile) AND !empty($uploadfile) AND isset($filename) AND !empty($filename)){
- echo $files;
- }
- $mail->send();
- $mail->ClearAllRecipients();
- $mail->clearReplyTos();
- $mail->ClearAttachments();
- // // 2.mail – Mail to the person who has written the mail.
- $mail->CharSet = "UTF-8";
- $mail->From = $from_mail;
- $mail->FromName = $from_name;
- $mail->addAddress($mailtoTwo); // Add a "To" address
- $mail->addReplyTo($replytoTwo); // Antwortadresse festlegen
- $mail->isHTML(true); // Mail als HTML versenden
- $mail->Subject = $subject;
- $mail->Body = $messageHTML;
- $mail->AltBody = $messageNoHTML;
- if(isset($uploadfile) AND !empty($uploadfile) AND isset($filename) AND !empty($filename)){
- echo $files;
- }
- $mail->send();
- $mail->ClearAllRecipients();
- $mail->clearReplyTos();
- $mail->ClearAttachments();
- go('grundstuck-verkaufen-success');
- // if(!$mail->send()) {
- // echo ':(!';
- // echo 'oops: ' . $mail->ErrorInfo;
- // } else {
- // go('grundstuck-verkaufen-success');
- // }
- } catch (RuntimeException $e) {
- echo $e->getMessage();
- }
- }
- else {
- echo "Token doesn't match";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement