Jump to content

Adobe Muse Contact Form – The server encountered an error


rasluht

Recommended Posts

Hi there, I already posted this in two different forums, but sadly know one can give me an answer, this is my next try.

I made a website in Muse bit I cant get the contact form to send the email. When you hit send it puts out an error.

The provider says it hast to be done over smtp, so i tried editing the existing form so math the requirements. but it just wont work.

Folder structure is main > scripts > PHPMailer-5.2.13 (files untouched)

Hope someone can help.

 

This is the code of the form_process.php:

<?php 
/* 	
If you see this text in your browser, PHP is not configured correctly on this hosting provider. 
Contact your hosting provider regarding PHP configuration for your site.

PHP file generated by Adobe Muse CC 2018.1.0.385
*/



function process_form($form) {
	if ($_SERVER['REQUEST_METHOD'] != 'POST')
		die(get_form_error_response($form['resources']['unknown_method']));

	
	
	// will die() if there are any errors
	check_required_fields($form);
	
	// will die() if there is a send email problem
	email_form_submission($form);
}

function get_form_error_response($error) {
	return get_form_response(false, array('error' => $error));
}

function get_form_response($success, $data) {
	if (!is_array($data))
		die('data must be array');
		
	$status = array();
	$status[$success ? 'FormResponse' : 'MusePHPFormResponse'] = array_merge(array('success' => $success), $data);
	
	return json_serialize($status);
}

function check_required_fields($form) {
	$errors = array();

	foreach ($form['fields'] as $field => $properties) {
		if (!$properties['required'])
			continue;

		if (!array_key_exists($field, $_REQUEST) || ($_REQUEST[$field] !== "0" && empty($_REQUEST[$field])))
			array_push($errors, array('field' => $field, 'message' => $properties['errors']['required']));
		else if (!check_field_value_format($form, $field, $properties))
			array_push($errors, array('field' => $field, 'message' => $properties['errors']['format']));
	}

	if (!empty($errors))
		die(get_form_error_response(array('fields' => $errors)));
}

function check_field_value_format($form, $field, $properties) {
	$value = get_form_field_value($field, $properties, $form['resources'], false);

	switch($properties['type']) {
		case 'checkbox':
		case 'string':
		case 'captcha':
			// no format to validate for those fields
			return true;

		case 'checkboxgroup':
			if (!array_key_exists('optionItems', $properties))
				die(get_form_error_response(sprintf($form['resources']['invalid_form_config'], $properties['label'])));

			// If the value received is not an array, treat it as invalid format
			if (!isset($value))
				return false;

			// Check each option to see if it is a valid value
			foreach($value as $checkboxValue) {
				if (!in_array($checkboxValue, $properties['optionItems']))
					return false;
			}

			return true;

		case 'radiogroup':
			if (!array_key_exists('optionItems', $properties))
				die(get_form_error_response(sprintf($form['resources']['invalid_form_config'], $properties['label'])));

			//check list of real radio values
			return in_array($value, $properties['optionItems']);
	
		case 'recaptcha':
			if (!array_key_exists('recaptcha', $form) || !array_key_exists('private_key', $form['recaptcha']) || empty($form['recaptcha']['private_key']))
				die(get_form_error_response($form['resources']['invalid_reCAPTCHA_private_key']));
			$resp = recaptcha_check_answer($form['recaptcha']['private_key'], $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
			return $resp->is_valid;

		case 'recaptcha2':
			if (!array_key_exists('recaptcha2', $form) || !array_key_exists('private_key', $form['recaptcha2']) || empty($form['recaptcha2']['private_key']))
				die(get_form_error_response($form['resources']['invalid_reCAPTCHA2_private_key']));

			$resp = recaptcha2_check_answer($form['recaptcha2']['private_key'], $_POST["g-recaptcha-response"], $_SERVER["REMOTE_ADDR"]);
			return $resp["success"];

		case 'email':
			return 1 == preg_match('/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i', $value);

		case 'radio': // never validate the format of a single radio element; only the group gets validated
		default:
			die(get_form_error_response(sprintf($form['resources']['invalid_field_type'], $properties['type'])));
	}
}

/**
 * Returns an object with following properties:
 *	"success": true|false,
 *	"challenge_ts": timestamp,  // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
 *	"hostname": string,         // the hostname of the site where the reCAPTCHA was solved
 *	"error-codes": [...]        // optional; possibe values:
 *									missing-input-secret - The secret parameter is missing
 *									invalid-input-secret - The secret parameter is invalid or malformed
 *									missing-input-response - The response parameter is missing
 *									invalid-input-response - The response parameter is invalid or malformed
 */
function recaptcha2_check_answer($secret, $response, $remoteIP) {
	$url = 'https://www.google.com/recaptcha/api/siteverify';
	$data = array(
		'secret' => $secret,
		'response' => $response,
		'remoteip' => $remoteIP
	);

	$options = array(
		'http' => array(
			'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
			'method'  => 'POST',
			'content' => http_build_query($data)
		)
	);
	
	$context = stream_context_create($options);
	$contents = file_get_contents($url, false, $context);
	if ($contents === FALSE) {
		die(get_form_error_response($form['resources']['invalid_reCAPTCHA2_server_response']));
	}

	$result = (array) json_decode($contents);
	return $result;
}

function email_form_submission($form) {
	if(!defined('PHP_EOL'))
		define('PHP_EOL', '\r\n');

	$form_email = ((array_key_exists('Email', $_REQUEST) && !empty($_REQUEST['Email'])) ? cleanup_email($_REQUEST['Email']) : '');

	$to = $form['email']['to'];
	$subject = $form['subject'];
	$message = get_email_body($subject, $form['heading'], $form['fields'], $form['resources']);
	$headers = get_email_headers($to, $form_email);	

	require 'PHPMailer-5.2.13/PHPMailerAutoload.php';
	$mail = new PHPMailer;
	$mail->isSMTP();
	$mail->Host = 'smtp.strato.de';
	$mail->SMTPAuth = true;
	$mail->Username = 'globaltest@jandecanthus.com';
	$mail->Password = 'xxx';
	$mail->SMTPSecure = 'ssl';
	$mail->Port = '465';  

	$mail->From = $form_email;
	$mail->FromName = $form_email;
	$mail->addAddress($to);
	$mail->isHTML(true);

	$mail->Subject = $subject;
	$mail->Body = $message;

	$sent = $mail->send();
	echo $mail->ErrorInfo;
	
	if(!$sent)
		die(get_form_error_response($form['resources']['failed_to_send_email']));
	
	$success_data = array(
		'redirect' => $form['success_redirect']
    );
	
	echo get_form_response(true, $success_data);
}

function get_email_headers($to_email, $form_email) {
	$headers = 'From: ' . $to_email . PHP_EOL;
	$headers .= 'Reply-To: ' . $form_email . PHP_EOL;
	$headers .= 'X-Mailer: Adobe Muse CC 2018.1.0.385 with PHP' . PHP_EOL;
	$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
	
	return $headers;
}

function get_email_body($subject, $heading, $fields, $resources) {
	$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	$message .= '<html xmlns="http://www.w3.org/1999/xhtml">';
	$message .= '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><title>' . encode_for_form($subject) . '</title></head>';
	$message .= '<body style="background-color: #ffffff; color: #000000; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: helvetica, arial, verdana, sans-serif;">';
	$message .= '<h2 style="background-color: #eeeeee;">' . $heading . '</h2>';
	$message .= '<table cellspacing="0" cellpadding="0" width="100%" style="background-color: #ffffff;">'; 

	$sorted_fields = array();
	
	foreach ($fields as $field => $properties) {
		// Skip reCAPTCHA from email submission
		if ('recaptcha' == $properties['type'] || 'recaptcha2' == $properties['type'])
			continue;

		array_push($sorted_fields, array('field' => $field, 'properties' => $properties));
	}

	// sort fields
	usort($sorted_fields, 'field_comparer');

	foreach ($sorted_fields as $field_wrapper)
		$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>' . encode_for_form($field_wrapper['properties']['label']) . ':</b></td><td>' . get_form_field_value($field_wrapper['field'], $field_wrapper['properties'], $resources, true) . '</td></tr>';

	$message .= '</table>';
	$message .= '<br/><br/>';
	$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) . '</div>';
	$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_by'], encode_for_form($_SERVER['REMOTE_ADDR'])) . '</div>';
	$message .= '</body></html>';

	return cleanup_message($message);
}

function field_comparer($field1, $field2) {
	if ($field1['properties']['order'] == $field2['properties']['order'])
		return 0;

	return (($field1['properties']['order'] < $field2['properties']['order']) ? -1 : 1);
}

function is_assoc_array($arr) {
	if (!is_array($arr))
		return false;
	
	$keys = array_keys($arr);
	foreach (array_keys($arr) as $key)
		if (is_string($key)) return true;

	return false;
}

function json_serialize($data) {

	if (is_assoc_array($data)) {
		$json = array();
	
		foreach ($data as $key => $value)
			array_push($json, '"' . $key . '": ' . json_serialize($value));
	
		return '{' . implode(', ', $json) . '}';
	}
	
	if (is_array($data)) {
		$json = array();
	
		foreach ($data as $value)
			array_push($json, json_serialize($value));
	
		return '[' . implode(', ', $json) . ']';
	}
	
	if (is_int($data) || is_float($data))
		return $data;
	
	if (is_bool($data))
		return $data ? 'true' : 'false';
	
	return '"' . encode_for_json($data) . '"';
}

function encode_for_json($value) {
	return preg_replace(array('/([\'"\\t\\\\])/i', '/\\r/i', '/\\n/i'), array('\\\\$1', '\\r', '\\n'), $value);
}

function encode_for_form($text) {
	$text = stripslashes($text);
	return htmlentities($text, ENT_QUOTES, 'UTF-8');// need ENT_QUOTES or webpro.js jQuery.parseJSON fails
}

function get_form_field_value($field, $properties, $resources, $forOutput) {
	$value = $_REQUEST[$field];
	
	switch($properties['type']) {
		case 'checkbox':
			return (($value == '1' || $value == 'true') ? $resources['checkbox_checked'] : $resources['checkbox_unchecked']);
		
		case 'checkboxgroup':
			if (!is_array($value))
				return NULL;

			$outputValue = array();

			foreach ($value as $checkboxValue)
				array_push($outputValue, $forOutput ? encode_for_form($checkboxValue) : stripslashes($checkboxValue));
			
			if ($forOutput)
				$outputValue = implode(', ', $outputValue);

			return $outputValue;
		
		case 'radiogroup':
			return ($forOutput ? encode_for_form($value) : stripslashes($value));
		
		case 'string':
		case 'captcha':
		case 'recaptcha':
		case 'recaptcha2':
		case 'email':
			return encode_for_form($value);

		case 'radio': // never validate the format of a single radio element; only the group gets validated
		default:
			die(get_form_error_response(sprintf($resources['invalid_field_type'], $properties['type'])));
	}
}

function cleanup_email($email) {
	$email = encode_for_form($email);
	$email = preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', null, $email);
	return $email;
}

function cleanup_message($message) {
	$message = wordwrap($message, 70, "\r\n");
	return $message;
}
?>

And this the code of the form-u9233.php:

<?php 
/* 	
If you see this text in your browser, PHP is not configured correctly on this hosting provider. 
Contact your hosting provider regarding PHP configuration for your site.

PHP file generated by Adobe Muse CC 2018.1.0.385
*/

require_once('form_process.php');

$form = array(
	'subject' => 'IOAN – Der Orden der Delphine Formular Übermittlung',
	'heading' => 'Neue Formularübermittlung',
	'success_redirect' => '',
	'resources' => array(
		'checkbox_checked' => 'Aktiviert',
		'checkbox_unchecked' => 'Nicht aktiviert',
		'submitted_from' => 'Von Website übermitteltes Formular: %s',
		'submitted_by' => 'Besucher-IP-Adresse: %s',
		'too_many_submissions' => 'Zu viele Sendungen in letzter Zeit von dieser IP',
		'failed_to_send_email' => 'E-Mail konnte nicht gesendet werden',
		'invalid_reCAPTCHA_private_key' => 'Ungültiger privater reCAPTCHA-Schlüssel.',
		'invalid_reCAPTCHA2_private_key' => 'Ungültiger privater reCAPTCHA 2.0-Schlüssel.',
		'invalid_reCAPTCHA2_server_response' => 'Ungültige private reCAPTCHA 2.0-Server-Reaktionszeit.',
		'invalid_field_type' => 'Unbekannter Feldtyp „%s“.',
		'invalid_form_config' => 'Die Konfiguration im Feld „%s“ ist ungültig.',
		'unknown_method' => 'Unbekannte Serveranfragemethode'
	),
	'email' => array(
		'from' => 'globaltest@jandecanthus.com',
		'to' => 'globaltest@jandecanthus.com'
	),
	'recaptcha2' => array(
		'private_key' => 'xxx'
	),
	'fields' => array(
		'custom_U9071' => array(
			'order' => 1,
			'type' => 'string',
			'label' => 'Name',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „Name“ ist erforderlich.'
			)
		),
		'Email' => array(
			'order' => 2,
			'type' => 'email',
			'label' => 'E-Mail',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „E-Mail“ ist erforderlich.',
				'format' => 'Die E-Mail-Adresse in Feld „E-Mail“ ist ungültig.'
			)
		),
		'custom_U9081' => array(
			'order' => 3,
			'type' => 'string',
			'label' => 'Nachricht',
			'required' => false,
			'errors' => array(
			)
		),
		'g-recaptcha-response' => array(
			'order' => 4,
			'type' => 'recaptcha2',
			'label' => 'Bildüberprüfung',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „Bildüberprüfung“ ist erforderlich.',
				'format' => 'Falscher reCAPTCHA 2.0-Wert.'
			)
		)
	)
);

process_form($form);
?>
Link to comment
Share on other sites

1 - Why is it that when people post here and mention "an error", they forget to show/tell us the ACTUAL ERROR MESSAGE?

 

2- When asking for help with a problem, it is quite a turn-off to have to review lines and lines of code that probably don't pertain to the actual problem. How about looking at the error message and if you can't figure that out, show us the area of the code where the error is coming from? Most php messages do provide the line number.

 

PS - be sure you have PHP error checking turned on during this development process so that you can easily be informed of many of the errors that do crop up while programming. See my signature.

Link to comment
Share on other sites

it just wont work

 

first of all, you have got to tell us what it does do. what output do you get when you run the code?

 

next, do you have php's error_reporting set to E_ALL and display_errors set to ON, so that php would help you by reporting and displaying all the errors it detects?

 

also -  

$form_email = ((array_key_exists('Email', $_REQUEST) && !empty($_REQUEST['Email'])) ? cleanup_email($_REQUEST['Email']) : '');
...
$mail->From = $form_email;
$mail->FromName = $form_email;

these emails are NOT being sent from the arbitrary email address that someone enter in a form (except maybe during testing.)  they are being sent from your sending mail server (even if the receiving mail server is the same.) the From: email address must correspond to the sending mail server, either directly (the same domain name) or there must be an SPF DNS zone record at the domain being used in the From: email address that says the sending mail server is authorized to send email for that domain.

 

you can put the entered email address into a Reply-to: mail header (which code is doing, but not actually using.)

Link to comment
Share on other sites

Hey guys, thanks for the reply.

Well the Error is: An Error occurred on the server.

If you can tell me, how I cant give you more Information, I will do so. How do I turn on the error reporting? I just put

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?> 

in front of the script?

Please remember I am a designer, no programmer.

@mac_gyver sorry, but I can't follow you. The E-Mail ist "globaltest@jandecanthus.com" and the Domain is "jandecanthus.com" so there should be no  problem here.

This is the website: https://www.jandecanthus.com/test/

Link to comment
Share on other sites

Do you know how to examine the various logs for your server? There might be additional information in there. "An error occurred on the server" is coming from application code somewhere, but unless we know the specific stack trace, or someone had access to your server or entire codebase, there is no way to know for sure.

 

I understand that you are a designer, but you still need to be able to debug your configuration. Otherwise, you might need to pay someone who has the expertise you are missing ;)

Link to comment
Share on other sites

FYI, I tested out your form (contact at the bottom of the page I assume?) and your server is issuing a 302 redirect. This appears to be a configuration issue possibly with whatever rewrite rules you have, so there may actually be no issue with your code. For some reason, after I posted the form, the response was a 302 back to the root of your site.

Link to comment
Share on other sites

Thanks, for testing.
I will write the provider now. I can't find any logs, the UI is pritty minimalistic, and It was a bad choice to take.

After I get an answer, I will write again.

And yes, I will prolly need to pay some coder here.

Link to comment
Share on other sites

So I found a programmer to help me with my problem.

It now works. It was done with Automailer. Just in case somebody has a similar problem, here is the code you have to change.

 

form_process.php:

<?php
/* 	
If you see this text in your browser, PHP is not configured correctly on this hosting provider. 
Contact your hosting provider regarding PHP configuration for your site.

PHP file generated by Adobe Muse CC 2018.0.0.379
*/

function process_form($form) {
	if ($_SERVER['REQUEST_METHOD'] != 'POST')
		die(get_form_error_response($form['resources']['unknown_method']));

	
	
	// will die() if there are any errors
	check_required_fields($form);
	
	// will die() if there is a send email problem
	email_form_submission($form);
}

function get_form_error_response($error) {
	return get_form_response(false, array('error' => $error));
}

function get_form_response($success, $data) {
	if (!is_array($data))
		die('data must be array');
		
	$status = array();
	$status[$success ? 'FormResponse' : 'MusePHPFormResponse'] = array_merge(array('success' => $success), $data);
	
	return json_serialize($status);
}

function check_required_fields($form) {
	$errors = array();

	foreach ($form['fields'] as $field => $properties) {
		if (!$properties['required'])
			continue;

		if (!array_key_exists($field, $_REQUEST) || ($_REQUEST[$field] !== "0" && empty($_REQUEST[$field])))
			array_push($errors, array('field' => $field, 'message' => $properties['errors']['required']));
		else if (!check_field_value_format($form, $field, $properties))
			array_push($errors, array('field' => $field, 'message' => $properties['errors']['format']));
	}

	if (!empty($errors))
		die(get_form_error_response(array('fields' => $errors)));
}

function check_field_value_format($form, $field, $properties) {
	$value = get_form_field_value($field, $properties, $form['resources'], false);

	switch($properties['type']) {
		case 'checkbox':
		case 'string':
		case 'captcha':
			// no format to validate for those fields
			return true;

		case 'checkboxgroup':
			if (!array_key_exists('optionItems', $properties))
				die(get_form_error_response(sprintf($form['resources']['invalid_form_config'], $properties['label'])));

			// If the value received is not an array, treat it as invalid format
			if (!isset($value))
				return false;

			// Check each option to see if it is a valid value
			foreach($value as $checkboxValue) {
				if (!in_array($checkboxValue, $properties['optionItems']))
					return false;
			}

			return true;

		case 'radiogroup':
			if (!array_key_exists('optionItems', $properties))
				die(get_form_error_response(sprintf($form['resources']['invalid_form_config'], $properties['label'])));

			//check list of real radio values
			return in_array($value, $properties['optionItems']);
	
		case 'recaptcha':
			if (!array_key_exists('recaptcha', $form) || !array_key_exists('private_key', $form['recaptcha']) || empty($form['recaptcha']['private_key']))
				die(get_form_error_response($form['resources']['invalid_reCAPTCHA_private_key']));
			$resp = recaptcha_check_answer($form['recaptcha']['private_key'], $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
			return $resp->is_valid;

		case 'recaptcha2':
			if (!array_key_exists('recaptcha2', $form) || !array_key_exists('private_key', $form['recaptcha2']) || empty($form['recaptcha2']['private_key']))
				die(get_form_error_response($form['resources']['invalid_reCAPTCHA2_private_key']));

			$resp = recaptcha2_check_answer($form['recaptcha2']['private_key'], $_POST["g-recaptcha-response"], $_SERVER["REMOTE_ADDR"]);
			return $resp["success"];

		case 'email':
			return 1 == preg_match('/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i', $value);

		case 'radio': // never validate the format of a single radio element; only the group gets validated
		default:
			die(get_form_error_response(sprintf($form['resources']['invalid_field_type'], $properties['type'])));
	}
}

/**
 * Returns an object with following properties:
 *	"success": true|false,
 *	"challenge_ts": timestamp,  // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
 *	"hostname": string,         // the hostname of the site where the reCAPTCHA was solved
 *	"error-codes": [...]        // optional; possibe values:
 *									missing-input-secret - The secret parameter is missing
 *									invalid-input-secret - The secret parameter is invalid or malformed
 *									missing-input-response - The response parameter is missing
 *									invalid-input-response - The response parameter is invalid or malformed
 */
function recaptcha2_check_answer($secret, $response, $remoteIP) {
	$url = 'https://www.google.com/recaptcha/api/siteverify';
	$data = array(
		'secret' => $secret,
		'response' => $response,
		'remoteip' => $remoteIP
	);

	$options = array(
		'http' => array(
			'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
			'method'  => 'POST',
			'content' => http_build_query($data)
		)
	);
	
	$context = stream_context_create($options);
	$contents = file_get_contents($url, false, $context);
	if ($contents === FALSE) {
		die(get_form_error_response($form['resources']['invalid_reCAPTCHA2_server_response']));
	}

	$result = (array) json_decode($contents);
	return $result;
}

function email_form_submission($form) {
	if(!defined('PHP_EOL'))
		define('PHP_EOL', '\r\n');

	$form_email = ((array_key_exists('Email', $_REQUEST) && !empty($_REQUEST['Email'])) ? cleanup_email($_REQUEST['Email']) : '');

	$to = $form['email']['to'];
	$subject = $form['subject'];
	$message = get_email_body($subject, $form['heading'], $form['fields'], $form['resources']);

	/*
	 * Originale Mailfunktion

	$sent = mail($to, $subject, $message, $headers);

	*/

	require('./PHPMailer-5.2.26/PHPMailerAutoload.php');
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
	//Tell PHPMailer to use SMTP
	$mail->isSMTP();
	//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 = $form['email']['mailserverhost'];
    $mail->SMTPSecure = "ssl";
	//Set the SMTP port number - likely to be 25, 465 or 587
	$mail->Port = 465;
	//Whether to use SMTP authentication
	$mail->SMTPAuth = true;
	//Username to use for SMTP authentication
	$mail->Username = $form['email']['mailserveruser'];
	//Password to use for SMTP authentication
	$mail->Password = $form['email']['mailserverpasswort'];
	//Set who the message is to be sent from
	$mail->setFrom($to);
	//Set an alternative reply-to address
	$mail->addReplyTo($form_email);
	//Set who the message is to be sent to
	$mail->addAddress($to);
	//Set the subject line
	$mail->Subject = $subject;
	//Read an HTML message body from an external file, convert referenced images to embedded,
	//convert HTML into a basic plain-text alternative body
	$mail->msgHTML($message);

    if(!$mail->send())
        die(get_form_error_response($form['resources']['failed_to_send_email']));

	$success_data = array(
		'redirect' => $form['success_redirect']
    );
	
	echo get_form_response(true, $success_data);

}

function get_email_headers($to_email, $form_email) {
	$headers = 'From: ' . $to_email . PHP_EOL;
	$headers .= 'Reply-To: ' . $form_email . PHP_EOL;
	$headers .= 'X-Mailer: Adobe Muse CC 2018.0.0.379 with PHP' . PHP_EOL;
	$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
	
	return $headers;
}

function get_email_body($subject, $heading, $fields, $resources) {
	$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	$message .= '<html xmlns="http://www.w3.org/1999/xhtml">';
	$message .= '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><title>' . encode_for_form($subject) . '</title></head>';
	$message .= '<body style="background-color: #ffffff; color: #000000; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: helvetica, arial, verdana, sans-serif;">';
	$message .= '<h2 style="background-color: #eeeeee;">' . $heading . '</h2>';
	$message .= '<table cellspacing="0" cellpadding="0" width="100%" style="background-color: #ffffff;">'; 

	$sorted_fields = array();
	
	foreach ($fields as $field => $properties) {
		// Skip reCAPTCHA from email submission
		if ('recaptcha' == $properties['type'] || 'recaptcha2' == $properties['type'])
			continue;

		array_push($sorted_fields, array('field' => $field, 'properties' => $properties));
	}

	// sort fields
	usort($sorted_fields, 'field_comparer');

	foreach ($sorted_fields as $field_wrapper)
		$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>' . encode_for_form($field_wrapper['properties']['label']) . ':</b></td><td>' . get_form_field_value($field_wrapper['field'], $field_wrapper['properties'], $resources, true) . '</td></tr>';

	$message .= '</table>';
	$message .= '<br/><br/>';
	$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_from'], encode_for_form($_SERVER['SERVER_NAME'])) . '</div>';
	$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">' . sprintf($resources['submitted_by'], encode_for_form($_SERVER['REMOTE_ADDR'])) . '</div>';
	$message .= '</body></html>';

	return cleanup_message($message);
}

function field_comparer($field1, $field2) {
	if ($field1['properties']['order'] == $field2['properties']['order'])
		return 0;

	return (($field1['properties']['order'] < $field2['properties']['order']) ? -1 : 1);
}

function is_assoc_array($arr) {
	if (!is_array($arr))
		return false;
	
	$keys = array_keys($arr);
	foreach (array_keys($arr) as $key)
		if (is_string($key)) return true;

	return false;
}

function json_serialize($data) {

	if (is_assoc_array($data)) {
		$json = array();
	
		foreach ($data as $key => $value)
			array_push($json, '"' . $key . '": ' . json_serialize($value));
	
		return '{' . implode(', ', $json) . '}';
	}
	
	if (is_array($data)) {
		$json = array();
	
		foreach ($data as $value)
			array_push($json, json_serialize($value));
	
		return '[' . implode(', ', $json) . ']';
	}
	
	if (is_int($data) || is_float($data))
		return $data;
	
	if (is_bool($data))
		return $data ? 'true' : 'false';
	
	return '"' . encode_for_json($data) . '"';
}

function encode_for_json($value) {
	return preg_replace(array('/([\'"\\t\\\\])/i', '/\\r/i', '/\\n/i'), array('\\\\$1', '\\r', '\\n'), $value);
}

function encode_for_form($text) {
	$text = stripslashes($text);
	return htmlentities($text, ENT_QUOTES, 'UTF-8');// need ENT_QUOTES or webpro.js jQuery.parseJSON fails
}

function get_form_field_value($field, $properties, $resources, $forOutput) {
	$value = $_REQUEST[$field];
	
	switch($properties['type']) {
		case 'checkbox':
			return (($value == '1' || $value == 'true') ? $resources['checkbox_checked'] : $resources['checkbox_unchecked']);
		
		case 'checkboxgroup':
			if (!is_array($value))
				return NULL;

			$outputValue = array();

			foreach ($value as $checkboxValue)
				array_push($outputValue, $forOutput ? encode_for_form($checkboxValue) : stripslashes($checkboxValue));
			
			if ($forOutput)
				$outputValue = implode(', ', $outputValue);

			return $outputValue;
		
		case 'radiogroup':
			return ($forOutput ? encode_for_form($value) : stripslashes($value));
		
		case 'string':
		case 'captcha':
		case 'recaptcha':
		case 'recaptcha2':
		case 'email':
			return encode_for_form($value);

		case 'radio': // never validate the format of a single radio element; only the group gets validated
		default:
			die(get_form_error_response(sprintf($resources['invalid_field_type'], $properties['type'])));
	}
}

function cleanup_email($email) {
	$email = encode_for_form($email);
	$email = preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', null, $email);
	return $email;
}

function cleanup_message($message) {
	$message = wordwrap($message, 70, "\r\n");
	return $message;
}
?>

form_process.php:

<?php 
/* 	
If you see this text in your browser, PHP is not configured correctly on this hosting provider. 
Contact your hosting provider regarding PHP configuration for your site.

PHP file generated by Adobe Muse CC 2018.0.0.379
*/

require_once('form_process.php');

$form = array(
	'subject' => 'KONTAKT Übermittlung',
	'heading' => 'Neue Formularübermittlung',
	'success_redirect' => '',
	'resources' => array(
		'checkbox_checked' => 'Aktiviert',
		'checkbox_unchecked' => 'Nicht aktiviert',
		'submitted_from' => 'Von Website übermitteltes Formular: %s',
		'submitted_by' => 'Besucher-IP-Adresse: %s',
		'too_many_submissions' => 'Zu viele Sendungen in letzter Zeit von dieser IP',
		'failed_to_send_email' => 'E-Mail konnte nicht gesendet werden',
		'invalid_reCAPTCHA_private_key' => 'Ungültiger privater reCAPTCHA-Schlüssel.',
		'invalid_reCAPTCHA2_private_key' => 'Ungültiger privater reCAPTCHA 2.0-Schlüssel.',
		'invalid_reCAPTCHA2_server_response' => 'Ungültige private reCAPTCHA 2.0-Server-Reaktionszeit.',
		'invalid_field_type' => 'Unbekannter Feldtyp „%s“.',
		'invalid_form_config' => 'Die Konfiguration im Feld „%s“ ist ungültig.',
		'unknown_method' => 'Unbekannte Serveranfragemethode'
	),
	'email' => array(
		'from' => 'email@server.com',
		'to' => 'email@server.com',
		'mailserveruser' => 'email@server.com',
		'mailserverpasswort' => 'password',
		'mailserverhost' => 'smtp.server.com'
	),
	'recaptcha2' => array(
		'private_key' => 'xxx'
	),
	'fields' => array(
		'custom_U1228' => array(
			'order' => 2,
			'type' => 'string',
			'label' => 'Name',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „Name“ ist erforderlich.'
			)
		),
		'Email' => array(
			'order' => 3,
			'type' => 'email',
			'label' => 'E-Mail',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „E-Mail“ ist erforderlich.',
				'format' => 'Die E-Mail-Adresse in Feld „E-Mail“ ist ungültig.'
			)
		),
		'custom_U1235' => array(
			'order' => 5,
			'type' => 'string',
			'label' => 'Nachricht',
			'required' => false,
			'errors' => array(
			)
		),
		'g-recaptcha-response' => array(
			'order' => 6,
			'type' => 'recaptcha2',
			'label' => 'Bildüberprüfung',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „Bildüberprüfung“ ist erforderlich.',
				'format' => 'Falscher reCAPTCHA 2.0-Wert.'
			)
		),
		'custom_U3785' => array(
			'order' => 4,
			'type' => 'string',
			'label' => 'Telefon',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „Telefon“ ist erforderlich.'
			)
		),
		'custom_U3984' => array(
			'order' => 1,
			'type' => 'string',
			'label' => 'Firma',
			'required' => true,
			'errors' => array(
				'required' => 'Feld „Firma“ ist erforderlich.'
			)
		)
	)
);

process_form($form);
?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.