-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformsubmit.module
More file actions
72 lines (61 loc) · 1.74 KB
/
formsubmit.module
File metadata and controls
72 lines (61 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file
* Contains formsubmit.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Implements hook_help().
*/
function formsubmit_help($route_name, RouteMatchInterface $route_match)
{
switch ($route_name) {
// Main module help for the formsubmit module.
case 'help.page.formsubmit':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('How to send an email programmatically') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_help().
*/
function formsubmit_message()
{
return "This is a message";
}
/**
* Implements hook_mail().
*/
function formsubmit_mail($name, $message, $to)
{
$msg['from'] = `alexisrengifo@gmail.com`;
$msg['company'] = 'My Company';
$msg['subject'] = t('Contact message sent:');
$msg['body'][] = $message;
$module = 'formsubmit';
$key = 'form_submit';
$params['message'] = $msg['body'];
$params['company'] = $msg['company'];
$send = TRUE;
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$mailManager = \Drupal::service('plugin.manager.mail');
// try {
$result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
if ($result['result'] !== true) {
// drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error');
return t('There was a problem sending your message and it was not sent.');
} else {
// drupal_set_message(t('Your message has been sent.'));
return t('Your message has been sent.');
}
// } catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n";
// return 'Caught exception: ' . $e->getMessage() . "\n";
// \Drupal::logger('my_module')->error($e->getMessage());
// return "";
// }
}