Form error message

Issues related to forms.
Post Reply
User avatar
alex4orly
 
 
Posts: 666
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Form error message

Post by alex4orly » Tue Jan 02, 2018 7:54 pm

I have a new form and get the error : PHPMailer error: Message body empty
I have no field in it called Body, or message - what is this?

Cheers

User avatar
Pablo
 
Posts: 16785
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Form error message

Post by Pablo » Tue Jan 02, 2018 10:09 pm

To be able to help you I need more details.
What is the URL?
What are your exact settings?
What is the generated PHP code?

User avatar
alex4orly
 
 
Posts: 666
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Form error message

Post by alex4orly » Tue Jan 02, 2018 10:51 pm

Hi Pablo,

1st I will say - the email message actually goes out, the error occurs after that.
2nd. It only started showing up only AFTER I added one field f0r the sender's email

The URL is : http://www.beleuramyhome.org.au/ To log in, use 400 for villa and 400a for password (this is my test account)
You get to the main screen - on the yellow line that ends with "Christmas Cheer" to the right there is small almost invisible link (Test mode now)

My settings didn't change, from before I added this new field (email)

Below is the genrated PHP code from WB - didn't make any manual changes to it
I followed a few Google search posts, none helped me

Thanks

<?php
if (session_id() == "")
{
session_start();
}
?>
<?php
require 'phpmailerautoload.php';
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
function ReplaceVariables($code)
{
foreach ($_POST as $key => $value)
{
if (is_array($value))
{
$value = implode(",", $value);
}
$name = "$" . $key;
$code = str_replace($name, $value, $code);
}
$code = str_replace('$ipaddress', $_SERVER['REMOTE_ADDR'], $code);
return $code;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'layoutgrid10')
{
$mailto = 'webmaster@beleuramyhome.org.au';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Residents going away report';
$message = '<strong>Hello Corryne,</strong><br><br><strong>We are going away</strong><br><br><strong>Villa Number :</strong> $Villa<br><strong>Residents : </strong>$Residents<br><strong>From Date : </strong>$FromDate<br><strong>To Date : </strong>$ToDate<br><br><strong>Contact Lendline : </strong>$Land_Line<br><strong>Contact Mobile : </strong>$Mobile_Phone<br><br><strong>Taking Caravan : </strong>$Caravan<br><br><strong>Cheers</strong><br>';
$success_url = './goingawayok.html';
$error_url = './goingawayerror.html';
$csvFile = "./goingaway.csv";
$error = '';
$autoresponder_from = '';
$autoresponder_to = isset($_POST['email']) ? $_POST['email'] : $mailfrom;
$autoresponder_subject = '';
$autoresponder_message = '';
$eol = "\n";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'mail.beleuramyhome.org.au';
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = 'webmaster@beleuramyhome.org.au';
$mail->Password = '3931morninG';
$subject = ReplaceVariables($subject);
$mail->Subject = stripslashes($subject);
$mail->From = $mailfrom;
$mail->FromName = $mailfrom;
$mailto_array = explode(",", $mailto);
for ($i = 0; $i < count($mailto_array); $i++)
{
if(trim($mailto_array[$i]) != "")
{
$mail->AddAddress($mailto_array[$i], "");
}
}
$mail->AddReplyTo($mailfrom);
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address is invalid!\n<br>";
}

if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}

$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$logdata = '';
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
$logdata .= ',';
if (!is_array($value))
{
$value = str_replace(",", " ", $value);
$logdata .= $value;
}
else
{
$logdata .= implode("|", $value);
}
}
}
$logdata = str_replace("\r", "", $logdata);
$logdata = str_replace("\n", " ", $logdata);
$logdata .= "\r\n";
$handle = fopen($csvFile, 'a') or die("can't open file");
$logtime = date("Y-m-d H:i:s,");
fwrite($handle, $logtime);
fwrite($handle, $_SERVER['REMOTE_ADDR']);
fwrite($handle, $logdata);
fclose($handle);
$mail->CharSet = 'ISO-8859-1';
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
}
}
}
$message = ReplaceVariables($message);
$message = stripslashes($message);
$mail->MsgHTML($message);
$mail->IsHTML(true);
if (!$mail->Send())
{
die('PHPMailer error: ' . $mail->ErrorInfo);
}
$mail->ClearAddresses();
$mail->ClearAttachments();
$autoresponder_subject = ReplaceVariables($autoresponder_subject);
$mail->Subject = stripslashes($autoresponder_subject);
$mail->From = $autoresponder_from;
$mail->FromName = $autoresponder_from;
$mail->AddAddress($autoresponder_to, "");
$mail->AddReplyTo($autoresponder_from);
$autoresponder_message = ReplaceVariables($autoresponder_message);
$autoresponder_message = stripslashes($autoresponder_message);
$mail->MsgHTML($autoresponder_message);
$mail->IsHTML(true);
if (!$mail->Send())
{
die('PHPMailer error: ' . $mail->ErrorInfo);
}
header('Location: '.$success_url);
exit;
}
?>

User avatar
Pablo
 
Posts: 16785
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Form error message

Post by Pablo » Wed Jan 03, 2018 8:13 am

I think the problem is related to the empty auto response message.
Either disable 'auto response' or enter something in the 'Message' field.

Note that 'auto response' also uses the 'email' input field, unless you have specified another field in the properties.

User avatar
alex4orly
 
 
Posts: 666
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Form error message

Post by alex4orly » Wed Jan 03, 2018 8:41 am

Spot on.... That was the reason
Just unchecked it, all good...

Why I didn't think of it, probably becasue tye nature of the error didn't give me any clue....

Thanks for your help

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests