Skip to content

Commit

Permalink
feat(): include from information in email body
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejpeters committed Oct 14, 2016
1 parent 92f8fd4 commit 6f6f3bc
Showing 1 changed file with 46 additions and 47 deletions.
93 changes: 46 additions & 47 deletions controllers/ContactFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,70 +69,69 @@ public function actionSendMessage()
}
elseif ($postedMessage)
{
if (is_array($postedMessage))
if (!is_array($postedMessage)) {
$postedMessage = array('body' => $postedMessage);
}

// Include from information in body
$postedMessage['From'] = "{$message->fromName} ({$message->fromEmail})";

// Capture all of the message fields on the model in case there's a validation error
$message->messageFields = $postedMessage;

// Capture the original message body
if (isset($postedMessage['body']))
{
// Capture all of the message fields on the model in case there's a validation error
$message->messageFields = $postedMessage;
// Save the message body in case we need to reassign it in the event there's a validation error
$savedBody = $postedMessage['body'];
}

// Capture the original message body
if (isset($postedMessage['body']))
{
// Save the message body in case we need to reassign it in the event there's a validation error
$savedBody = $postedMessage['body'];
}
// If it's false, then there was no messages[body] input submitted. If it's '', then validation needs to fail.
if ($savedBody === false || $savedBody !== '')
{
// Compile the message from each of the individual values
$compiledMessage = '';

// If it's false, then there was no messages[body] input submitted. If it's '', then validation needs to fail.
if ($savedBody === false || $savedBody !== '')
foreach ($postedMessage as $key => $value)
{
// Compile the message from each of the individual values
$compiledMessage = '';

foreach ($postedMessage as $key => $value)
if ($key != 'body')
{
if ($key != 'body')
if ($compiledMessage)
{
if ($compiledMessage)
{
$compiledMessage .= "\n\n";
}

$compiledMessage .= $key.': ';

if (is_array($value))
{
$compiledMessage .= implode(', ', $value);
}
else
{
$compiledMessage .= $value;
}
$compiledMessage .= "\n\n";
}
}

if (!empty($postedMessage['body']))
{
if ($compiledMessage)
$compiledMessage .= $key.': ';

if (is_array($value))
{
$compiledMessage .= "\n\n";
$compiledMessage .= implode(', ', $value);
}
else
{
$compiledMessage .= $value;
}
}
}

$compiledMessage .= $postedMessage['body'];
if (!empty($postedMessage['body']))
{
if ($compiledMessage)
{
$compiledMessage .= "\n\n";
}

$message->message = $compiledMessage;
$compiledMessage .= $postedMessage['body'];
}
}
else
{
$message->message = $postedMessage;
$message->messageFields = array('body' => $postedMessage);

$message->message = $compiledMessage;
}
}

if (empty($message->htmlMessage))
{
$message->htmlMessage = StringHelper::parseMarkdown($message->message);
}
if (empty($message->htmlMessage))
{
$message->htmlMessage = StringHelper::parseMarkdown($message->message);
}

if ($message->validate())
{
Expand Down

0 comments on commit 6f6f3bc

Please sign in to comment.