I'm using the notify_entity module for Drupal 8 and want to change the mail address used for the from value.
I'm trying to do it using hook_mail_alt r but it doesn't work, Drupal still send mail with the default administrator mail address... Am I doing something wrong? Or there is another way to do this?
Thanks.
/**
* Implements hook_mail_alter()
*/
function notify_entity_mail_alter(&$message){
$from = "foo#bar.com";
$message['from'] = $from;
}
They should be changed like this
$message['headers']['Return-Path'] = 'user#email.com';
$message['headers']['Sender'] = 'user#email.com';
$message['headers']['From'] = 'Site name';
$message['headers']['Reply-to'] = 'user#email.com';
Also note it seems you are modifying (hacking) the notify_entity module right ? You should not do that! If you update it or someone else updates this drupal installation in the future you might end up losing the changes and not realize it ...
You should create your own module and implement the hook_mail_alter and name your function MYMODULE_mail_alter()
Just today I had to do this and stumbled upon your question here it is a very simple module that does exactly what you want https://github.com/GiorgosK/mail_alter_headers.
NOTE: you have to modify the .module file with your own details or comment out // the ones you don't want to modify.
Related
I am trying to add a Logic Hook for Emails synced from IMAP Mail server.
In the end i want trigger a hook when a new mail gets synced and check the senders mail if its saved in one of the accounts.
The problem is that the Synced Mails dont get saved (at least not in InboundMail or Emails module) so the after/before_save does not trigger.
Here is my hook from logic_hooks.php:
$hook_array['after_save'][] = Array(1, 'Create Lead', 'custom/modules/InboundEmail/LeadLogicHook.php', 'LeadLogicHook', 'handleLead');
It does not work in InboundEmail and Email Module.
And the LeadLogicHook:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class LeadLogicHook
{
function handleLead($bean, $event, $arguments)
{
_ppl("Test");
}
}
Is this even possible with logic hooks?
EDIT: Added some Code
No need for logic hook or any other custom code. Sugar/SuiteCRM use a scheduler job to fetch email from IMAP server. You can check scheduler job function (function::pollMonitoredInboxes) which fetch emails. That contain code which is used for email fetching. track back code and you will find everything you want.
What version of sugar are you using?
You can, for example, generate an after_save hook in the E-mail module instead of inboundEmail
Would be like this:
$hook_array ['after_save'] [] = Array (1,'Create Lead','custom/modules/Emails/LeadLogicHook.php','LeadLogicHook','handleLead');
Do this and see if the email fires!
Another possibility would be to use the after_relationship_add, because usually, the email is associated with some lead, account, or contact. try to create a hook in the module that your email is associating with and generate the operation from there
one last possibility (I do not recommend this) is to create a trigger in your database for when the data enters the table, perform the check and take some action
I think it's possible, if after/before_save not triggering then try some similar logic hooks. The following are some logic hooks that I think could help.
before_retrieve
after_retrieve
before_restore
after_restore
server_roundtrip
after_session_start
after_entry_point
Comment if you want more details, like how to use logic hooks e.t.c.
In Prestashop 1.6, from a FrontController, I have to send a mail to the administrator of the Shop.
This part works well but I got problems to include a link to the administration page of a specific customer.
The only thing I miss is the name of the administration directory. I would be able to parse and concatenate the PS_ADMIN_DIR constant but it is not available from the FrontController.
I'm kinda stuck here.
Here is the code :
$admin_customer_link =
_PS_BASE_URL_
.__PS_BASE_URI__
/* Missing the Administration directory name here */
.$this->context->link->getAdminLink('AdminCustomers', false)
."&id_customer=".(int)$customer->id."&viewcustomer";
The output I got :
http://127.0.0.1:8080/prestashop/index.php?controller=AdminCustomers&id_customer=2&viewcustomer
The output I need :
http://127.0.0.1:8080/prestashop/administration/index.php?controller=AdminCustomers&id_customer=2&viewcustomer
Any help will be appreciated.
There is no (standard) way to know the administration folder from a front controller, otherwise all the security will flushed down the toilet :).
What you can do is to retrieve the administration folder from the module 'configuration' or when you install it, and save it somewhere, at the moment I suggest into the database but maybe there is a more safely mode.
Something like:
public function install()
{
// your stuff
$current_dir = $_SERVER['PHP_SELF']; // this give you the current dir (administration folder included)
$administration_folder = /* Clean your string with a string replace or preg */
Configuration::updateValue('PS_MYMOD_ADMIN_DIR', $administration_folder);
return true;
}
Then in your front controller retrieve it by:
$adminfolder = Configuration::get('PS_MYMOD_ADMIN_DIR');
However I hope you know that you're creating a security breach through e-mail...
Hope it helps
Since the use of the administration directory name from the Front End and sending a link to the administration in e-mail is not a good idea for security purpose, I choose to implement this another way.
Instead of send the administration customer's page link to the webmaster by e-mail, I create a new customer Thread and message. After that, I send an e-mail to the customer service. So, when they log in the Back Office, they see a new notification who leads them to the specific user.
Here is the code :
ModuleFrontController
// Create a new Customer Thread
$ct = new CustomerThread();
if (isset($customer->id)) {
$ct->id_customer = (int)$customer->id;
}
$ct->id_shop = (int)$this->context->shop->id;
$ct->id_contact = $contact->id;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $customer->email;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
// Add a new message to the Customer Thread
if ($ct->id) {
$cm = new CustomerMessage();
$cm->id_customer_thread = $ct->id;
$cm->message = $message;
$cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
$cm->add();
}
Hope it helps someone in the same situation.
The problem is that mailing on my site didt work.
There is code to sending mail
....
$params['subject'] = $mail_subject;
$params['body'] = $mail_body;
$to = 'dmitriikotow#gmail.com'
$from = 'mail#ckeverest.ru';
$lang = language_default();
drupal_mail('everest_mail', 'html_mail', $to, $lang, $params, $from, false);
....
There is custom mail-module code
<?php
class EverestMailSystem extends DefaultMailSystem {
public function format(array $message) {
$message['body'] = implode("\n\n", $message['body']);
$message['body'] = drupal_wrap_mail($message['body']);
return $message;
}
}
function everest_mail_mail($key, &$message, $params) {
switch ($key) {
case 'html_mail':
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
break;
}
}
?>
At first glance, everything should work. There is a suspicion that the problem is outside of the module, as sending messages to work until the last update the appearance of the site (I have not participated in the update). As the module was not written by me, so I need the opinion of a more experienced programmer than I am.
In any case, I would like to know. Where can I find useful in my case the logs site? And with their help to catch a mistake?
Thank you so much.
Drupal uses a module called watchdog to handle logging (D8 and earlier). There are a few ways to access these logs:
If you are using Drush, you can simply type drush ws to see a list of the most recent 10(ish) log entries. (pro tip: each log entry has an id and if you type drush ws [ID] you can see more details)
There is a module that ships with Drupal called "Database logs" or "DB Logs". If you enable this module you will get a "view recent log messages" page under the "report" menu item. DO NOT enable this module on a production site except as an absolute last resort.
I'm 99% sure that Drupal's watchdog logs are piped into you system log so you should be able to get them in there as well. In OSX (ahem) MacOS you can use the Console Application to view logs, or just use tail on the command line to tail your system logs
hope that helps
I need to change
logo_url
for transactional emails with external link, for example
https://exampledomainname.com/image.png
but I can't hardcode all or even one file in
app/locale
Is there any way to add external url as logo_url? As when I go here:
System > Configuration > General > Design > Transactional Emails
I can only add image to hosting area
As far as I was looking into the web there is no best practice way to directly rewrite logo_url, but we can create custom variable and then use it into email templates. We can do it manually from admin or using programming way. My requirements is to implement this in programming way, so we start with shell script(shell\external_logo_url.php) to create custom variable:
<?php
require_once '../abstract.php';
class External_Logo_Url extends Mage_Shell_Abstract
{
public function run()
{
$variable = Mage::getModel('core/variable')
->setCode('variable-code')
->setName('variable-name')
->setPlainValue('variable-value')
->save();
}
}
$shell = new External_Logo_Url();
$shell->run();
Also we need to change template files in app\locale, so you need replace all template files or custom templates that you need. You should look for {{var logo_url}} and replace with {{customVar code=variable-code}}.
Im trying to get the email stored udner 'settings' in wordpress. I know there was an old function for this: get_settings but this is depreciated. I can't find a replacement - is there a reason for this? What is the best practice method for returning the settings email in wordpress?
Instead of using get_settings(), use get_option().
Example:
$email = get_option('admin_email');