Index: app/controllers/CControllerPopupMediatypeTestSend.php
===================================================================
--- app/controllers/CControllerPopupMediatypeTestSend.php	(revision 91230)
+++ app/controllers/CControllerPopupMediatypeTestSend.php	(working copy)
@@ -49,53 +49,71 @@
 		return ($this->getUserType() == USER_TYPE_SUPER_ADMIN);
 	}
 
-	protected function doAction() {
-		global $ZBX_SERVER, $ZBX_SERVER_PORT;
-
+	protected function getInputMediaType() {
 		$mediatype = API::MediaType()->get([
 			'output' => ['type'],
 			'mediatypeids' => $this->getInput('mediatypeid'),
 			'filter' => ['status' => MEDIA_STATUS_ACTIVE]
 		]);
-		$result = true;
-		$msg_title = null;
 
-		if ($mediatype) {
-			$mediatype = reset($mediatype);
+		return reset($mediatype);
+	}
 
-			if ($mediatype['type'] == MEDIA_TYPE_EMAIL) {
-				$email_validator = new CEmailValidator();
+	protected function validateInputMediaType(array $mediatype, &$error) {
+		if ($mediatype['type'] == MEDIA_TYPE_EMAIL) {
+			$email_validator = new CEmailValidator();
 
-				if (!$email_validator->validate($this->getInput('sendto'))) {
-					$result = false;
-					error($email_validator->getError());
-				}
+			if (!$email_validator->validate($this->getInput('sendto'))) {
+				$error = $email_validator->getError();
+				return false;
 			}
+		}
 
-			if ($result) {
-				$server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT);
-				$result = $server->testMediaType([
-						'mediatypeid' => $this->getInput('mediatypeid'),
-						'sendto' =>	$this->getInput('sendto'),
-						'subject' => $this->getInput('subject'),
-						'message' => $this->getInput('message')
-					],
-					get_cookie('zbx_sessionid')
-				);
+		return true;
+	}
 
-				if ($result) {
-					info(_('Media type test successful.'));
-				}
-				else {
-					$msg_title = _('Media type test failed.');
-					error($server->getError());
-				}
-			}
+	protected function sendServerRequest(&$error) {
+		global $ZBX_SERVER, $ZBX_SERVER_PORT;
+
+		$server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT);
+		$result = $server->testMediaType([
+			'mediatypeid' => $this->getInput('mediatypeid'),
+			'sendto' =>	$this->getInput('sendto'),
+			'subject' => $this->getInput('subject'),
+			'message' => $this->getInput('message')
+			],
+			get_cookie('zbx_sessionid')
+		);
+
+		if (!$result) {
+			$error = $server->getError();
+			return false;
 		}
-		else {
-			$result = false;
+
+		return true;
+	}
+
+	protected function doAction() {
+
+		$mediatype = $this->getInputMediaType();
+
+		$result = false;
+		$msg_title = null;
+
+		if (!$mediatype) {
 			error(_('No permissions to referred object or it does not exist!'));
 		}
+		elseif (!$this->validateInputMediaType($mediatype, $error)) {
+			error($error);
+		}
+		elseif (!$this->sendServerRequest($error)) {
+			error($error);
+			$msg_title = _('Media type test failed.');
+		}
+		else {
+			$result = true;
+			info(_('Media type test successful.'));
+		}
 
 		$output = [
 			'user' => [
Index: app/views/popup.mediatypetest.edit.js.php
===================================================================
--- app/views/popup.mediatypetest.edit.js.php	(revision 91230)
+++ app/views/popup.mediatypetest.edit.js.php	(working copy)
@@ -27,15 +27,17 @@
  */
 function mediatypeTestSend(formname) {
 	var form = window.document.forms[formname],
-		url = new Curl(jQuery(form).attr('action'));
+		$form = jQuery(form),
+		$formfields = $form.find('#sendto, #subject, #message'),
+		url = new Curl($form.attr('action'));
 
-	jQuery(form).trimValues(['#sendto', '#subject', '#message']);
+	$form.trimValues(['#sendto', '#subject', '#message']);
 
 	jQuery.ajax({
 		url: url.getUrl(),
-		data: jQuery(form).serialize(),
+		data: $form.serialize(),
 		beforeSend: function() {
-			jQuery(form).find('#sendto, #subject, #message').prop('disabled', true);
+			$formfields.prop('disabled', true);
 
 			jQuery('<span></span>')
 				.addClass('preloader')
@@ -50,14 +52,14 @@
 				.hide();
 		},
 		success: function(ret) {
-			jQuery(form).parent().find('.msg-bad, .msg-good').remove();
+			$form.parent().find('.msg-bad, .msg-good').remove();
 
 			if (typeof ret.messages !== 'undefined') {
-				jQuery(ret.messages).insertBefore(jQuery(form));
-				jQuery(form).parent().find('.link-action').click();
+				jQuery(ret.messages).insertBefore($form);
+				$form.parent().find('.link-action').click();
 			}
 
-			jQuery(form).find('#sendto, #subject, #message').prop('disabled', false);
+			$formfields.prop('disabled', false);
 
 			jQuery('.preloader').remove();
 			jQuery('.submit-test-btn')
Index: include/classes/server/CZabbixServer.php
===================================================================
--- include/classes/server/CZabbixServer.php	(revision 91230)
+++ include/classes/server/CZabbixServer.php	(working copy)
@@ -188,10 +188,12 @@
 		return $this->request([
 			'request' => 'alert.send',
 			'sid' => $sid,
-			'mediatypeid' => $data['mediatypeid'],
-			'sendto' => $data['sendto'],
-			'subject' => $data['subject'],
-			'message' => $data['message']
+			'data' => [
+				'mediatypeid' => $data['mediatypeid'],
+				'sendto' => $data['sendto'],
+				'subject' => $data['subject'],
+				'message' => $data['message']
+			]
 		]);
 	}
 
