Setting a Form in Adobe Muse for limited PHP server

Hi There!,
I’m designing a website in Muse for a dance festival and forms are really important. This is the site: http://www.videodanzaba.com.ar/videodanzaba--esp.html

The problem is i’ve always used hostings that supported PHP fully, but this website needs to be hosted in a local host and it has gave me lots of trouble.

The site is located in DonWeb (Argentinian server).
My Forms don’t work because as they have said to me:

"Unfortunately our we had to modify the php fonction mail () configuration in our servers, due to the vulnerabilities of the forms of lots of users, which always ended in blocking the server’s IP because of spam, damaging the whole network.

Pleas modify your form with the next tips:

  • Do not specify mail and password, leaving both empty
    (“”) if an authentication error appears when sending.

  • Use “localhost” as server’s host.

  • Insert in the fonction mail () previous line:

ini_set(sendmail_from,‘test@dom.com’);

In this way you’ll configurate correctly your From, because it is not allowed to configure a FROM that is different from the mail account (To avoid FROM falsification)"

When sending from the web, a PHP config. error appears.
I’ve read this topic: Script won't send Email
But i’m not getting results, maybe i’m doing something wrong as i really don’t understand coding…

If you are so kind, maybe you can help me to make my forms work properly.

I’ll pase the form_process.php below as i can upload files yet, because i’m new.
THANKS!


<?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 2014.2.1.284
*/

require_once('form_throttle.php');

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

	if (formthrottle_too_many_submissions($_SERVER['REMOTE_ADDR']))
		die(get_form_error_response($form['resources']['too_many_submissions']));
	
	// 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) || 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']);

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

		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 '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);

		default:
			die(get_form_error_response(sprintf($form['resources']['invalid_field_type'], $properties['type'])));
	}
}

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);	

	$sent = @mail($to, $subject, $message, $headers);
	
	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 2014.2.1.284 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;">'; 

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

		$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>' . encode_for_form($properties['label']) . ':</b></td><td>' . get_form_field_value($field, $properties, $resources) . '</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 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) {
	return htmlentities($text, ENT_COMPAT, 'UTF-8');
}

function get_form_field_value($field, $properties, $resources) {
	$value = $_REQUEST[$field];
	
	switch($properties['type']) {
		case 'checkbox':
			return (($value == '1' || $value == 'true') ? $resources['checkbox_checked'] : $resources['checkbox_unchecked']);
		
		case 'string':
		case 'captcha':
		case 'recaptcha':
		case 'email':
			return encode_for_form($value);

		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;
}
?>

Well they tell you in your email to put a line before your mail() call. And you havent done that. So… first do what the hosting company told you to do? Your mail doesnt appear to be using authentication, so you can skip that part.

Hi, StarLion!, That script is the original Muse process script. The thing is i can’t find where to change those values they ask me to…
that’s why i ended up in that post i’ve mentioned. I tried to modify de function email as ‘cpradio’ said, but i didn’t got any results. I simply don’t know how to code, i’m a designer, not a coder yet, so that’s why i’m asking for help, maybe you can show me where in that script do i have to put/change the information my hosting provider is asking me to…

Thanks again

Okay first let’s try the suggestion from your host, as that wouldn’t require phpmailer

Find this line

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

and replace it with

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

Hi, cpradio!, thanks for helping me with this,
I’ve just tried what you said and replaced those lines, but still nothing.

No idea if this will make a difference, but try replacing

ini_set(sendmail_from, $to);

with

ini_set('sendmail_from', $to);

Thanks, but still nothing :frowning:
don’t i have to change somewhere the server’s host to ‘localhost’?

i’m really lost with this…

Okay, I’m going to suggest we go a different route now. As the ini_set isn’t working that great.

So start with downloading phpMailer from https://github.com/Synchro/PHPMailer/archive/v5.2.8.zip

Unzip it and FTP the entire PHPMailer-5.2.8 folder to the same folder that includes your Muse script.

Then in your muse script find these lines

ini_set('sendmail_from', $to);
$sent = @mail($to, $subject, $message, $headers);

And replace them with:

	require 'PHPMailer-5.2.8/PHPMailerAutoload.php';  
	$mail = new PHPMailer;
	$mail->isSMTP();
	$mail->Host = 'removed'; // update this line
	$mail->SMTPAuth = true;
	$mail->Username = 'removed'; // update this line
	$mail->Password = 'removed'; // update this line
	// $mail->SMTPSecure = 'tls'; // leave this commented out

	$mail->From = 'test@sdfencing.co.uk'; // update this line
	$mail->FromName = 'test@sdfencing.co.uk'; // update this line
	$mail->addAddress($to);
	$mail->isHTML(true);

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

	$sent = $mail->send();
1 Like

OK!, so, before i make stupid mistakes i need to check this (really really thanks for your patience):

-As they’ve told me, i leave user and password empty, like this → ‘’
-when they say: use 'localhost, it’s literally speaking ‘localhost’ or do i put my server’s name?
-and finally, From & FromName: do i put my email account (contacto@videodanzaba.com.ar) or that’s where “test@dom.com” plays its role?.. is test@dom.com just a manner of speaking and i have to replace it with something else?

To my knowledge test@dom.com is just a “placeholder” so you’d replace it with your email address.

As for the Server credentials. Set $mail->Host to “localhost”, and comment out the lines of $mail->SMTPAuth, $mail->Username, $mail->Password.

like this?

require ‘PHPMailer-5.2.8/PHPMailerAutoload.php’;
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = ‘localhost’;
/*
$mail->SMTPAuth = true;
$mail->Username = ’’;
$mail->Password = ‘’;
$mail->SMTPSecure = 'tls’;
*/

$mail->From = ‘contacto@videodanzaba.com.ar’;
$mail->FromName = ‘contacto@videodanzaba.com.ar';
1 Like

Yes

OK. So this is what i’ve tried the first time, following the other topic.
But it doesn’t work for me.
Now, in addition to my form’s error message, another sign appears.

Any idea of why i’m still getting errors?
Should i contact my host again?
I’ve just talk to them but they won’t help me… not a really good host…their help center is awful…

I have other php scripts: form_ check, form_throttle and some with numbers, for ex: form_u2595.php

Can you post the script you edited in its entirety here? Remove any confidential information (such as your email address, or anything you don’t want public).

Or if it is more convenient PM me the whole script and I’ll post what is relevant here.

Sure, I have other php scripts: form_ check, form_throttle and some with numbers, for ex: form_u2595.php
I don’t know if maybe they need to be modified too. My contact form is set to send mails to multiple accounts: one of my hosting company and other gmail’s… could that be a problem?

Heres my 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 2014.2.1.284
*/

require_once('form_throttle.php');

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

	if (formthrottle_too_many_submissions($_SERVER['REMOTE_ADDR']))
		die(get_form_error_response($form['resources']['too_many_submissions']));
	
	// 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) || 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']);

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

		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 '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);

		default:
			die(get_form_error_response(sprintf($form['resources']['invalid_field_type'], $properties['type'])));
	}
}

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.8/PHPMailerAutoload.php';  
	$mail = new PHPMailer;
	$mail->isSMTP();
	$mail->Host = ‘localhost’;
	/*
	$mail->SMTPAuth = true;
	$mail->Username = ‘’;
	$mail->Password = ‘’;
	$mail->SMTPSecure = 'tls’;
	*/

	$mail->From = ‘example@example.com’;
	$mail->FromName = ‘example@example.com';
	$mail->addAddress($to);
	$mail->isHTML(true);

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

	$sent = $mail->send();
	
	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 2014.2.1.284 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;">'; 

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

		$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>' . encode_for_form($properties['label']) . ':</b></td><td>' . get_form_field_value($field, $properties, $resources) . '</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 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) {
	return htmlentities($text, ENT_COMPAT, 'UTF-8');
}

function get_form_field_value($field, $properties, $resources) {
	$value = $_REQUEST[$field];
	
	switch($properties['type']) {
		case 'checkbox':
			return (($value == '1' || $value == 'true') ? $resources['checkbox_checked'] : $resources['checkbox_unchecked']);
		
		case 'string':
		case 'captcha':
		case 'recaptcha':
		case 'email':
			return encode_for_form($value);

		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;
}
?>

Okay, so it may be your editor that you used for PHP. The following lines have weird quotation marks.

	$mail->Host = ‘localhost’;
	/*
	$mail->SMTPAuth = true;
	$mail->Username = ‘’;
	$mail->Password = ‘’;
	$mail->SMTPSecure = 'tls’;
	*/

	$mail->From = ‘example@example.com’;
	$mail->FromName = ‘example@example.com';

Replace them with

	$mail->Host = 'localhost';
	/*
	$mail->SMTPAuth = true;
	$mail->Username = '';
	$mail->Password = '';
	$mail->SMTPSecure = 'tls';
	*/

	$mail->From = 'example@example.com';
	$mail->FromName = 'example@example.com';

OK. now the sign i attached before doesn’t shows anymore, but the for is still saying the mail could not be sent…
should i try to avoid multiple email accounts in my form or that has nothing to do with this?
by the way: i’m using Mac’s TextEdit… thought it was ok!

Can you elaborate on this a bit more? A screenshot of what you entered if on your website’s form or are you putting multiple From/To email addresses?

When i created the website , In Muse’s form widget i put 2 different addresses separated by commas for the form to be sent at. It is supposed to work, because It’s a valid option in Muse, and i’ve never experimented any Problem with this on my other websites, but i wonder if maybe particularly in this case should i leave just one address, the one hosted in DonWeb…

Thanks for your help,
i finally found it was more effective to use jotform for this contact form instead of keep trying this time.