Hi I am Chris and I come from the UK, I have been thrown head first into web design, my good friend of 22 years passed away suddenly, and I agreed to help one of his clients out hosting a site, this gave me an interest in designing sites, so much so I had a go at building one for my son in adobe muse, and I am pretty proud of the result, I have one issue though with the web form created within muse, (see attached image) although the form sends to email fine, I get a popup error message, Fasthosts cannot help me as they say it is a script error, basically I exported the site to html which gave me a folder with 4 .php scripts in, everything was uploaded using WS_ftp pro, I have gone through the code in the 4 scripts but cannot see anything I can adjust to try and solve this issue, searching on the web also reveals a lot of other people have this problem but noone seems to have solved it. I'm not after a quick fix, I would like to solve this myself "IF" I am able to, maybe with a few pointers, or if anyone has actually solved this?, here is the contact page if anyone wants to see the error, http://tomjauncey.co.uk/contact.html thank you, and I look forward to being a part of this community, Chris.
Your contact form is expecting to be processed by a script at scripts/form-u742.php This won't be a hosting issue, find that file and upload it and you should be good to go
Hi Sarah, thank you for the reply, yes that is one of the 4 scripts I uploaded with the site, this is what is puzzling me.
Then your problem might be where it's positioned. Personally I'd never have a script referenced by "scripts/", I much prefer "/scripts/". It's a subtle difference but the leading "/" tells the browser to start at http://tomjauncey.co.uk/ and then look for scripts and then look for the file. Without the leading "/" it could potentially be looking for a scripts folder inside another folder. So looking at your server I was able to get feedback on that file (I didn't check earlier) Inside modern browsers there is an "inspect" tool that gives you information about the page you are visiting (I apologise if I'm teaching you how to suck eggs but you said you were relatively new) So we know the script exists but we know the server doesn't like it. We also know you didn't write it so your next step is either to wade through the generated code or go back into muse (which I haven't used) and check all the settings, the email address it's sending to, and how it's sending the email. If there's nothing obvious a screenshot of the config panel might be useful. If you look at the code you can put debug points in there and see where it breaks. Typically I'd put a var_dump and exit in at logical points and see where it breaks and therefore it's the code between my last successful run and the one that just broke. var_dump($somevariable); exit; Code (markup):
Good morning Sarah, Sorry for the delay in replying but it was night time here in the UK, and I had been staring at that page all day and had gotten a little disheartened. You are definately NOT teaching me how to suck eggs, and I appreciate your help, I have not worked in code so I need to understand your instructions, which I don't at the moment. I did go through the 4 php files yesterday to see if anything lept out out me, FastHosts told me I searched through the code in the scripts but could find no reference to this, for me it is a bit like looking through steamed up glasses, I can see something is going on but it is all fuzzy. I can do a screenshot, but when you say config panel what do you mean, sorry if I appear dumb, many thanks Sarah. Chris.
Hi Chris I waded through the muse code and the spot where I expected to find something juicy is in form_process.php 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); } Code (markup): Every looks as it should so my next step would be to copy this into a file, put your email address in it, upload and run <?php mail('myemail@email.com','Test Email: '.time(),'Test Email'); Code (markup): You'll either get a test email or you'll get that error too. Over the years I've used, or had clients who use, a wide variety of shared hosts. We've never needed to set the email server for a mail() command.
I saved that script as a cj_mail.php changed the email in it, uploaded it to the server, and then ran it in the browser which gave this error, and we got no email back.
That's a blessing in disguise, the muse contact form was a red herring - but good to have that detail. @PoPSiCLe have you seen something like this before?
I got another response from Fasthosts, " Dear Chris Can you ask your developer to specify the smtp server instead on the mail script and use the smtp details below and see if it makes any difference. smtp = websmtp.livemail.co.uk Port = 25 Hope this helps. Best regards, El Nino Fasthosts Customer Support
500 Internal server errors usually means the script fails with a fatal error - if we had access to the server-logs, this would be easy to figure out, as the Apache error-log (or the PHP-specific one, if set) will contain something which would tell us what breaks. @ChrisJ7 could you post the entire cj_mail.php file in [ code ] boxes here? I can't really be arsed downloading the entire thing and looking for stuff. Most likely, it's something simple like a missing ; on the end of a code line, or somewhere someone has written : when they meant ;, some concatination-error creating a unclosed {} or something like that.
Here is the code from the test script. <?php mail('info@tomjauncey.co.uk','Test Email: '.time(),'Test Email'); Code (markup): I'm really starting to pull my hair out, what little I have, I have been staring at the 4 scripts adobe muse generates for days, as I don't like being beat, but this is way beyond me to fix, but my head is just puddled, thank you for assisting @PoPSiCLe
I also found this page on the FastHosts website if it helps , https://help.fasthosts.co.uk/app/answers/detail/a_id/59/kw/php the 4 scripts adobe muse generates for the form widget are: form_check.php form_process.php form_throttle.php form-u472.php I can put up the code to anyone of those if it helps? and I have asked FastHosts if they can send me the part of the server error log where the error occurs.
Hm. Do you have any other .php-files running on that server? I see you're running Microsoft IIS (why?) - that MIGHT be part of the problem, however I have next to no experience running PHP on IIS. There might be something in the files that isn't compatible with IIS, or the IIS-server isn't set up to handle PHP properly. That, however, would be something to take up with Fasthost. To check if PHP is up and running correctly, you can try the following: Create a new file, call it phpinfo.php, and paste in the following code: <?php phpinfo(); ?> PHP: And access it in a browser. It should show a purple/gray info statement about PHP on the server.
I don't have any other php files running on that domain, but I do on another site?, which I presume is on the same server? that is running on Linux (I just checked), or maybe not as this one is running on windows, but i believe I can change back to linux for the tomjauncey.co.uk one. (EDIT) looks like I can change tomjauncey.co.uk over to a linux server, is it worth a try? Here is the top part of the results or do you want the whole thing to look at? it is quite a long statement?
If you can swap to a linux server without anything else happening to your site, I would test it just to be sure - there is really no reason to run on IIS unless you're gonna do ASP-pages, or have some other specific needs - you'll probably get better and faster updates to core services on Apache, however I have no experience with Fasthost. As I said in msg, post the form-files' code as well, maybe there is an issue somewhere in it.
here is the code, form_u472.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.0.0.309 */ require_once('form_process.php'); $form = array( 'subject' => 'CONTACT Form Submission', 'heading' => 'New Form Submission', 'success_redirect' => '', 'resources' => array( 'checkbox_checked' => 'Selected', 'checkbox_unchecked' => 'Unselected', 'submitted_from' => 'Form submitted from website: %s', 'submitted_by' => 'Visitor IP address: %s', 'too_many_submissions' => 'Too many recent submissions from this IP', 'failed_to_send_email' => 'Failed to send email', 'invalid_reCAPTCHA_private_key' => 'Invalid reCAPTCHA private key.', 'invalid_field_type' => 'Unknown field type \'%s\'.', 'invalid_form_config' => 'Field \'%s\' has an invalid configuration.', 'unknown_method' => 'Unknown server request method' ), 'email' => array( 'from' => 'info@myemail.co.uk', 'to' => 'info@tmyemail.co.uk' ), 'fields' => array( 'custom_U751' => array( 'order' => 1, 'type' => 'string', 'label' => 'Name', 'required' => true, 'errors' => array( 'required' => 'Field \'Name\' is required.' ) ), 'Email' => array( 'order' => 2, 'type' => 'email', 'label' => 'Email', 'required' => true, 'errors' => array( 'required' => 'Field \'Email\' is required.', 'format' => 'Field \'Email\' has an invalid email address.' ) ), 'custom_U747' => array( 'order' => 3, 'type' => 'string', 'label' => 'Message', 'required' => false, 'errors' => array( ) ) ) ); process_form($form); ?> PHP:
That, in itself, doesn't seem to be problematic. Could you post the form_process.php as well? Since that file you show there only sets up an array, and the only processing happens with the form_processing file and the function process_form, I'm guessing that the problem lies there, more than in that file.
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 2015.0.0.309 */ 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'], 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.0.0.309 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; } ?> PHP: