Jump to content

Hook for when user send message in contact form


Recommended Posts

Contact from is a module and does not have any hooks afaik. You can either create an override for the module or use hook actionEmailSendBefore in Mail function e.g. filtering for $template to identify that it's coming from contact form.

Link to comment
Share on other sites

So i have this:

	// Mail hook trigger
	public function actionEmailSendBefore($param) {
		
		// Webhook code (working)
		$url = "WEBHOOK_URL_HERE";
		$headers = [ 'Content-Type: application/json; charset=utf-8' ];
		$POST = [ 'username' => 'Testing BOT', 'content' => 'Testing message' ];
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($POST));
		$response   = curl_exec($ch);
		
	}

but it doesn't run the code. What is a easy way to check if "actionEmailSendBefore" gets triggerd?

Link to comment
Share on other sites

I did register the webhook as seen below here but with no result 

	// Gets called when module gets installed
	public function install()
	{	
		// Register actionEmailSendBefore hook
		return parent::install() && $this->registerHook("actionEmailSendBefore");
	}

Hmm, gonna look into Hook::exec! Also i see online everywhere "hook" before public funtion hookhere.

Edited by kelvindereus (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...