I am using Muse to help me learn webdesign and hope to learn php/ coding as I go along.
I have created a test site and added a contact form. The site was uploaded to my server but the form wont work as it required smtp authentication. I have set smtp autentication via my web panel (password etc…) but now require code to be added to the muse form script. I havent got a clue how to do this as Iam learning. I do have this info from my host Link here and after digging around I’m sure that this code controls the Muse form.
<?php
/*
If you see this text in your browser, PHP is not configured correctly on this webhost.
Contact your hosting provider regarding PHP configuration for your site.
*/
require_once('form_throttle.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (formthrottle_too_many_submissions($_SERVER["REMOTE_ADDR"]))
{
echo '{"MusePHPFormResponse": { "success": false,"error": "Too many recent submissions from this IP"}}';
}
else
{
emailFormSubmission();
}
}
function emailFormSubmission()
{
if(!defined('PHP_EOL'))
define('PHP_EOL', '\\r\
');
$to = 'removed';
$subject = 'Contact Form Submission';
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><title>' . htmlentities($subject,ENT_COMPAT,'UTF-8') . '</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;">New Form Submission</h2><table cellspacing="0" cellpadding="0" width="100%" style="background-color: #ffffff;">';
$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>Name:</b></td><td>' . htmlentities($_REQUEST["custom_U205"],ENT_COMPAT,'UTF-8') . '</td></tr>';
$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>Email:</b></td><td>' . htmlentities($_REQUEST["Email"],ENT_COMPAT,'UTF-8') . '</td></tr>';
$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>Message:</b></td><td>' . htmlentities($_REQUEST["custom_U211"],ENT_COMPAT,'UTF-8') . '</td></tr>';
$message .= '<tr><td valign="top" style="background-color: #ffffff;"><b>Phone:</b></td><td>' . htmlentities($_REQUEST["custom_U267"],ENT_COMPAT,'UTF-8') . '</td></tr>';
$message .= '</table><br/><br/>';
$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">Form submitted from website: ' . htmlentities($_SERVER["SERVER_NAME"],ENT_COMPAT,'UTF-8') . '</div>';
$message .= '<div style="background-color: #eeeeee; font-size: 10px; line-height: 11px;">Visitor IP address: ' . htmlentities($_SERVER["REMOTE_ADDR"],ENT_COMPAT,'UTF-8') . '</div>';
$message .= '</body></html>';
$message = cleanupMessage($message);
$formEmail = cleanupEmail($_REQUEST['Email']);
$headers = 'From: removed' . PHP_EOL . 'Reply-To: ' . $formEmail . PHP_EOL .'X-Mailer: Adobe Muse 2014.0.30 with PHP/' . phpversion() .'/'. PHP_OS . PHP_EOL . 'Content-type: text/html; charset=utf-8' . PHP_EOL;
$sent = @mail($to, $subject, $message, $headers);
if($sent)
{
echo '{"FormResponse": { "success": true,"redirect":"index.html"}}';
}
else
{
echo '{"MusePHPFormResponse": { "success": false,"error": "Failed to send email"}}';
}
}
function cleanupEmail($email)
{
$email = htmlentities($email,ENT_COMPAT,'UTF-8');
$email = preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\\
|\\\\r)\\S).*=i', null, $email);
return $email;
}
function cleanupMessage($message)
{
$message = wordwrap($message, 70, "\\r\
");
return $message;
}
?>
The homepage for PHPMailer even shows an SMTP authentication example, so it should be relatively easy to see how to replace your @mail(…) with the PHPMailer exmaple.
Ok Think i’m following. With PHPMailer do I download just the PHPMailerAutoload.php file and put in in the same folder? then alter the code as you highlighted?
Download the zip file of the latest release. Extract it, and copy it to your server (you can leave it in the PHPMailer-5.2.8 folder if you wish. That won’t harm anything, but if you do, edit the following line from my code:
require 'PHPMailerAutoload.php';
Would then read as (so it includes the folder name)
require 'PHPMailer-5.2.8/PHPMailerAutoload.php';
If you run into issues, post your updated code (remove any username and password/any other private information) and I’ll be glad to review it.
When running your form, I’m using Chrome (because I like their dev tools). So before I submit the form, I hit F12 to get the Dev Tools opened, go to the Network Tab, then submit the form and you’ll see a request for form-u203.php appear in the Network section. Click on it. Click on Preview and you’ll see the output from your form submission
TLS would alter how the data gets sent, if TLS isn’t supported (and potentially the port it uses), then it would fail. It seems your host doesn’t use TLS. I only figured that out after watching their video on setting up your email in Thunderbird and they didn’t check the TLS encryption option
FYI: You may want to alter your error message to be
echo '{"MusePHPFormResponse": { "success": false,"error": "Failed to send email"}}';