function createResponse() { if (ob_get_contents()) { ob_clean(); } $response = array(); $response['error'] = 0; $response['field'] = array(); $Validation = new PBValidation(); $Session = new PBSession(); $Session->create(); $id = $_POST['id']; $formMetaData = $Session->getValue($this->getComponentId(), $id); if ($formMetaData === false) { exit; } $response['debug'] = $formMetaData['debug']; $response['reset'] = $formMetaData['reset']; if (!array_key_exists('field', $formMetaData)) { exit; } if (!is_array($formMetaData['field'])) { exit; } if (!count($formMetaData['field'])) { exit; } $response['notice']['error'] = $formMetaData['notice']['error']; $response['notice']['success'] = $formMetaData['notice']['success']; $replace = array(); foreach ($formMetaData['field'] as $fieldIndex => $fieldData) { if ($fieldData['type'] == 'submit') { continue; } if (!array_key_exists($fieldIndex, $_POST)) { $response['error'] = 1; continue; } $value = $_POST[$fieldIndex]; if ($Validation->isNotEmpty($fieldData['name'])) { if (!array_key_exists($fieldData['name'], $replace)) { $replace[$fieldData['name']] = $value; } } if ($fieldData['type'] == 'email') { if ($Validation->isNotEmpty($value) || $fieldData['mandatory'] == 1) { if (!$Validation->isEmailAddress($value)) { $response['error'] = 1; $response['field'][$fieldIndex]['notice'] = $fieldData['notice']; } } } else { if ($fieldData['mandatory'] == 1) { if ($Validation->isEmpty($value)) { $response['error'] = 1; $response['field'][$fieldIndex]['notice'] = $fieldData['notice']; } } } } if ($response['error'] == 1) { PBHelper::ajaxResponse($response); } PBInclude::includeClass(PLUGIN_PAGE_BUILDER_LIBRARY_PATH . 'phpMailer/PHPMailerAutoload.php', array('PHPMailer')); $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; foreach ($replace as $index => $value) { $formMetaData['sender']['name'] = preg_replace('/\\(' . $index . '\\)/', $value, $formMetaData['sender']['name']); $formMetaData['sender']['email'] = preg_replace('/\\(' . $index . '\\)/', $value, $formMetaData['sender']['email']); } if ($Validation->isEmailAddress($formMetaData['sender']['email']) && $Validation->isNotEmpty($formMetaData['sender']['name'])) { $mail->SetFrom($formMetaData['sender']['email'], $formMetaData['sender']['name']); $mail->AddReplyTo($formMetaData['sender']['email'], $formMetaData['sender']['name']); } $mail->AddAddress($formMetaData['recipient']['email'], $formMetaData['recipient']['name']); $recipientAdditionalData = mb_split(';', $formMetaData['recipient']['additional']); foreach ($recipientAdditionalData as $value) { $recipientAdditional = mb_split(':', $value); PBHelper::removeUIndex($recipientAdditional, 0, 1); if ($Validation->isEmailAddress($recipientAdditional[1]) && $Validation->isNotEmpty($recipientAdditional[0])) { $mail->AddAddress($recipientAdditional[1], $recipientAdditional[0]); } } if ($formMetaData['debug'] == 1) { $mail->SMTPDebug = true; } if ($Validation->isNotEmpty($formMetaData['sender']['smtp_host'])) { $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Port = $formMetaData['sender']['smtp_port']; $mail->Host = $formMetaData['sender']['smtp_host']; $mail->Username = $formMetaData['sender']['smtp_username']; $mail->Password = $formMetaData['sender']['smtp_password']; $mail->SMTPSecure = $formMetaData['sender']['smtp_secure_connection_type']; } $mail->Subject = $formMetaData['message_subject']; $value = array_map('htmlspecialchars', $replace); $body = $formMetaData['message_content']; foreach ($replace as $index => $value) { $body = preg_replace('/\\[' . $index . '\\]/', $value, $body); } $mail->MsgHTML(apply_filters('the_content', $body)); if (!$mail->Send()) { $response['error'] = 1; PBHelper::ajaxResponse($response); } PBHelper::ajaxResponse($response); }