Muse Emailing Form not Working - "PHP error"

@cpradio I created a website on Adobe Muse CC and the form is not working properly. I saw the threads for other people where you have guided them on what to do, but my situation is a bit different. Also I am just learning code, so I know nothing :frowning:

I have one hosting provider for the website and a different hosting provider for the emails. I have contacted the hosting provider for the website and they said I have to add a SMTP script so my form knows it has to send the emails to the server of the email hosting people.

Also, in my scripts folder, I don’t have the PHPMailer folder. I just have .php files

I don’t know if this makes any sense

Thank you!!

Okay, so it sounds very familiar to this topic

In which case, you will need to download the latest version of PHPMailer

Once you download it, extract the folder inside the zip file and upload it to your server with your other PHP Files (the entire folder).

Then you will follow these instructions (click the down arrow to see it properly without having to navigate to the other topic)

Since you will be uploading the folder, your require statement will be require 'PHPMailer-5.2.13/PHPMailerAutoload.php';

The rest of the changes will be you putting in the correct SMTP host, username and password (along with the appropriate From and FromName.

Thank you very much. I will try this and let you know if I run into any trouble. We always used another web hosting provider and the same for web and emails, never had this problem. Thanks again :smile:

1 Like

This is what the file looks like:

<?php
/**
 * PHPMailer SPL autoloader.
 * PHP Version 5
 * @package PHPMailer
 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
 * @author Brent R. Matzelle (original founder)
 * @copyright 2012 - 2014 Marcus Bointon
 * @copyright 2010 - 2012 Jim Jagielski
 * @copyright 2004 - 2009 Andy Prevost
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 * @note This program is distributed in the hope that it will be useful - WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * PHPMailer SPL autoloader.
 * @param string $classname The name of the class to load
 */
function PHPMailerAutoload($classname)
{
    //Can't use __DIR__ as it's only in PHP 5.3+
    $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
    if (is_readable($filename)) {
        require $filename;
    }
}

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
    //SPL autoloading was introduced in PHP 5.1.2
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        spl_autoload_register('PHPMailerAutoload', true, true);
    } else {
        spl_autoload_register('PHPMailerAutoload');
    }
} else {
    /**
     * Fall back to traditional autoload for old PHP versions
     * @param string $classname The name of the class to load
     */
    function __autoload($classname)
    {
        PHPMailerAutoload($classname);
    }
}

*The change you are saying, is it here?*

{
    //Can't use __DIR__ as it's only in PHP 5.3+
    $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
    if (is_readable($filename)) {
        require 'PHPMailer-5.2.13/PHPMailerAutoload.php';
    }
}

thanks!

That is the PHPMailerAutoload file, are you looking for the file to replace Muse mail command?

If so, I’m going to need to know what PHP file(s) Muse had you put on your website, and then I might be able to gleam which one is the one you want to edit.

I have 4 form_ .php files:

form_check.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 2015.1.2.344
*/

require_once('form_throttle.php');

if ($_SERVER['REQUEST_METHOD'] == 'GET') 
{
	$supportResponse = checkSupport();
	if (!empty($_GET['mode']) and $_GET['mode'] == 'verify')
	{
		echo $supportResponse;
		exit;
	}
	
	echo('<!DOCTYPE html><html><head><title>Muse PHP Diagnostics</title>');
	echo('<style type="text/css">body { font: 14pt Myriad Pro, Arial, Helvetica;}ul { list-style-type: none; }');
	echo(' h1 { background-color: #CCCCCC; padding: 2px;} label {display: inline-block; width: 100px; vertical-align: top;}');
	echo('.good:before { color: green; content:\'\2713\0020\';} .bad:before {color: red; content: \'X\0020\';}');
	echo('</style></head><body>');
	echo('<h1>Diagnostics</h1><ul>');
	
	if (strrpos($supportResponse,'PHP:0;') === false)
	{
		echo('<li class="bad">PHP version too low');
	}
	else 
	{ 
		echo('<li class="good">PHP version ok');
	}
	if (strrpos($supportResponse,'Mail:0;') === false)
	{
		echo('<li class="bad">Mail configuration: PHP mail() configured incorrectly on server. Form will not be able to send email.');
	}
	else
	{
		echo('<li class="good">Mail configuration: No known problems detected with php mail configuration.');
	}
	
	if (strrpos($supportResponse,'SQL:1;') !== false)
	{
		echo('<li class="bad">Spam control: SQLite not found. Form may send email successfully, but limiting spam submissions by IP address will not work.');
	}
	else if (strrpos($supportResponse,'SQL:8;') !== false)
	{
		echo('<li class="bad">Spam control: Cannot write to scripts directory. Form may send email successfully, but limiting spam submissions by IP address will not work.');
	}
	else if (strrpos($supportResponse,'SQL:0;') === false)
	{
		echo('<li class="bad">Spam control: SQL configuration problem. Form may send email successfully, but limiting spam submissions by IP address will not work.');
	}
	else 
	{ 
		echo('<li class="good">Spam control: Emails will be limited to 25 in 2 hours from the same IP address.');
	}
	echo('</ul><br/><br/>');
	
	echo('</body></html>');
}

$phpError = '';
function phpErrorHandler($errno, $errstr, $errfile, $errline)
{
	global $phpError;
    if (!(error_reporting() & $errno)) 
    {
        return;
    }

    $phpError .= $errstr;
    return true;
}

function checkSupport()
{	
	global $phpError;
	set_error_handler("phpErrorHandler");
		
	$response = '';
	$throttleSupport = formthrottle_check();
	$response ='SQL:' . $throttleSupport . ';';

	$version = explode('.', PHP_VERSION);
	if ($version[0] < 4 || ($version[0] == 4 && $version[1] < 1))
	{
		$response .='PHP:1;';
		return $response;
	}
	else 
	{ 
		$response .='PHP:0;';
	}

	if (strncasecmp(php_uname('s'), 'win', 3) == 0) 
	{ 
		$mailserver = ini_get('SMTP');
	}
	else
	{
		$mailserver = ini_get('sendmail_path');
	}
	if (strlen($mailserver) == 0)
	{
		$response .='Mail:1;';
	}
	else
	{
		if (!function_exists("mail")) 
		{ 
			$response .='Mail:2;';
		}  
		else
		{
			$sent = mail("recipient@example.com", "Hi", "test message", "From: sender@example.com");
			if($sent)
			{
				$response .='Mail:0;';
			}
			else
			{
				$response .='Mail:3;';			
			}
		}
	}
			
	if($phpError != '')
	{
		$response .='PHPError:' . $phpError;
	}

	return $response;
}
?>
  1. form_process
<?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 2015.1.2.344
*/

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) || ($_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 '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'])));
	}
}

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 2015.1.2.344 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'])
			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 '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;
}
?>
  1. form_throttle.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 2015.1.2.344
*/

function formthrottle_check()
{
	if (!is_writable('.'))
	{
		return '8';
	}

	try
	{
	    if (in_array("sqlite",PDO::getAvailableDrivers(),TRUE))
		{
			$db = new PDO('sqlite:muse-throttle-db.sqlite3');
			if ( file_exists('muse-throttle-db') )
			{
				unlink('muse-throttle-db');
			}
		}
		else if (function_exists("sqlite_open")) 
		{
			$db = new PDO('sqlite2:muse-throttle-db');
			if ( file_exists('muse-throttle-db.sqlite3') )
			{
				unlink('muse-throttle-db.sqlite3');
			}
		} else {
			return '4';
		}
	}
	catch( PDOException $Exception ) {
		return '9';
	}

	$retCode ='5';
	if ($db) 
	{
		$res = $db->query("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Submission_History';");
		if (!$res or $res->fetchColumn() == 0)
	    {
			$created = $db->exec("CREATE TABLE Submission_History (IP VARCHAR(39), Submission_Date TIMESTAMP)");

			if($created == 0)
			{
				$created = $db->exec("INSERT INTO Submission_History (IP,Submission_Date) VALUES ('256.256.256.256', DATETIME('now'))");
			}
			
			if ($created != 1)
			{
				$retCode = '2';
			}
		}
		if($retCode == '5')
		{
			$res = $db->query("SELECT COUNT(1) FROM Submission_History;");
			if ($res && $res->fetchColumn() > 0)
			{
				$retCode = '0';
			}
			else
				$retCode = '3';
		}

		// Close file db connection
 		$db = null;
	} 
	else
		$retCode = '4';
		
	return $retCode;
}	

function formthrottle_too_many_submissions($ip)
{
	$tooManySubmissions = false;

	try
	{
		if (in_array("sqlite",PDO::getAvailableDrivers(),TRUE))
		{
			$db = new PDO('sqlite:muse-throttle-db.sqlite3');
		}
		else if (function_exists("sqlite_open")) 
		{
			$db = new PDO('sqlite2:muse-throttle-db');
		} else {
			return false;
		}
	}
	catch( PDOException $Exception ) {
		return $tooManySubmissions;
	}

	if ($db) 
	{
		$res = $db->query("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Submission_History';");
		if (!$res or $res->fetchColumn() == 0)
	    {
			$db->exec("CREATE TABLE Submission_History (IP VARCHAR(39), Submission_Date TIMESTAMP)");
		}
		$db->exec("DELETE FROM Submission_History WHERE Submission_Date < DATETIME('now','-2 hours')");

		$stmt = $db->prepare("INSERT INTO Submission_History (IP,Submission_Date) VALUES (:ip, DATETIME('now'))");
		$stmt->bindParam(':ip', $ip);
		$stmt->execute();
		$stmt->closeCursor();

		$stmt = $db->prepare("SELECT COUNT(1) FROM Submission_History WHERE IP = :ip;");
		$stmt->bindParam(':ip', $ip);
		$stmt->execute();
		if ($stmt->fetchColumn() > 25) 
			$tooManySubmissions = true;
		// Close file db connection
 		$db = null;
	}
	return $tooManySubmissions;
}
?>

form_process seems to be the file. Give me a moment, I’ll provide more specific steps.

Of course, thank you so much!!

Okay, so inside form_process.php

There is a line with this (approximately line #115)

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

Replace that line with (be sure to update the lines that have // update this line)

	require 'PHPMailer-5.2.13/PHPMailerAutoload.php';
	$mail = new PHPMailer;
	$mail->isSMTP();
	$mail->Host = 'smtp.example.com'; // update this line
	$mail->SMTPAuth = true;
	$mail->Username = 'myusername@example.com'; // update this line
	$mail->Password = 'mysecretpassword'; // update this line
	$mail->SMTPSecure = 'tls';

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

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

	$sent = $mail->send();

for the host - my email hosting provider said their server is mail.hover.com, does that look right? Also, for username and password, i should have the log in for the email I want the form to send the emails to right?

yes

yes

Perfect!!
Would i have to alter the PHPMailerAutoload file also, or just this one and add the PHPMailer folder to my scripts folder?

Just that one. Once you alter it and upload both that modified file and the PHPMailer folder, it should work.

1 Like

sorry for the delay, I had to get the password for that email, since it’s not mine. I added the whole PHPMailer folder I downloaded from the link you gave me to my scripts folder and I made the changes to the form_process file but now I get an error message right on the browser “Form PHP script is missing from web server, or PHP is not configured correctly”. Before it was just the form that said “the server encountered an error”, now a little window popped-up and said that. would it be like it happened to someone else that i have to do // before the line that says: “$mail->SMTPSecure = ‘tls’;” ?

I don’t know how to quote from other threads, if possible, but this is what you said to him:

Okay, try it after commenting out the following line:

$mail->SMTPSecure = ‘tls’;
So that line should look like:

//$mail->SMTPSecure = ‘tls’;

Should I try it? Also, I erased the text " // update this line"

Tried it anyway and it didn’t work. I still get the same error message

Seems when you uploaded it back, you either accidentally named it something else or put it in the wrong folder…

but i named it exactly the same and put it on the same folder - i edited the file on text edit externally, does it have to be edited in the server?