SMS with Twilio API

Hello everyone,

I just need to know if it’s true that we can’t integrate Twilio API with Mautic for SMS automation on a shared hosting? I can’t seem to find that answer and my host tells me that I need a dedicated server.

I also have another question, what would be the best way to have the content of a form sent to an admin SMS mobile number right from the form action which I don’t see an option other than sending an email to a particular email address. Also through campaign automation, I see options to send a text message so maybe withe a Webhook as there’s an option for it in automation again to send the content of the form to an admin via SMS.

Thanks for sharing your knowledge

John

Its recommended to run Mautic on dedicated server, because of the administration of instance and all the dependencies Mautic has. Your life is easier when you can customize the server to suit your requirements.

That is not to say its imposible to run Mautic on shared hosting, I have seen posts of people saying that installed Mautic on shared hoting.

I do not see any reason why you could not host Twilio plugin on a shared hosting. If you can get Mautic to work on a shared hosting then Twilio will also work.

SMS sending is handled by leavering Mautic core & transport plugin (in your case Twilio). You cannot and you should not send SMS directly from form action.

Now that being said with a little bit of development youcan make form submit trigger SMS send in Mautic, that is possible, but you wil have to extend the Mautic with custom plugin.

Thanks for the reply Mzagmajster!

I also think that you can use Twilio API in Mautic for SMS services but for some reason this company won’t allow it, I tested it and it doesn’t work.

As for sending SMS form content to an admin, I had a programmer code something right in the action form option where you can add email recipients right under it, there was an option to : send sms form content and it use to work very well. Unfortunately I changed server and lost the old Mautic installation.

Can’t we just create a Webhook in the campaign automation option with a PHP script instead of custom plugin? Thanks

So form submit is the first thing that happens. When data comes to Mautic that can trigger another action which can be SMS send.

It could be done, but sending of SMS is handled by Mautic via third party integration.

In webhooks for now you have the ability to setup webhook on form submit event:

So I guess if you would really want it, you could setup so that this goes out to a custom php script and then handle SMS sending in php script.

But using the SMS transport within mautic I think its still a better option.

Thanks for this reply Mzagmajster!

I had a php script created with the help of ChatGPT not sure how good it is, I added the url of the script in that field : Webhook POST Url and when testing it says: error detected. I also tried from the campaign automation, there’s also an option for send a webhook and again I get an error in the event page of the contact.

That is the script I used:

<?php // Set your SMS gateway API credentials $smsApiKey = 'MyAPIFromTwilioHere'; $apiUrl = 'https://lookups.twilio.com/v2/PhoneNumbers/+phonenumberTwilio'; $adminPhoneNumber = 'adminPhoneNumber; // Replace with the actual admin's phone number // Get lead data from Mautic $leadData = json_decode(file_get_contents('php://input'), true); // Customize SMS content based on lead data $nomComplet = $leadData['fields']['nom_complet']['value']; $adresse = $leadData['fields']['adresse']['value']; $telephoneMobile = $leadData['fields']['telephone_mobile']['value']; $courriel = $leadData['fields']['courriel']['value']; $joursToSell = implode(', ', $leadData['fields']['30_jours']); $smsContent = "New form submission\nNom Complet: $nomComplet\nAdresse: $adresse\nTéléphone Mobile: $telephoneMobile\nCourriel: $courriel\nQuand voulez-vous vendre?: $joursToSell"; // Send SMS using cURL or other methods provided by the SMS gateway $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "apiKey=$smsApiKey&message=$smsContent&phone=$adminPhoneNumber"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // Log response or perform any additional actions // ... // Return a response (optional) echo $response; ?>


In any case I can’t even get the SMS function to work, in my campaign automation I use the option: Send text message just to test SMS functions but I never receive the text, but in the event section of that test contact I see SMS sent 100%, also I don’t receive the welcome email, please see screenshot, could it be the cron? Which one is for SMS message or they’re are none , I use these crons: - 0,15,30,45 <— mautic:segments:update

You get an error because response probably does not have the right response.

Anyway the script that you pasted has nothing to do with Mautic.

It just a plain php script that sends an SMS data directly to twilio. You could paste url to this cusotm script in the form or anywhere really and it should send the contact.

I am not even sure how you managed to get test sms event log in mautic using this.

You are reinventing the wheel, just use twilio plugin that integrates with mautic and that is all.

Might I ask what hosting is this that does not allow Twilio plugin but allows custom scripts? Something does not make sense to me here.

I believe you need to have, mautic:broadcasts:send cron to send SMS, but I know there is some issue sending segment emails with it on Mautic 4.x.

Thanks for getting back and for the info. So after many tries I decided to go for a VPS with Ionos and using Ubuntu and Apache, now more headaches, I managed to install everything and when I go to the URL for the installer /installer and get an all white page if I can bypass that issue then I’ll start configuring Twilio and Mautic again and test. You are mentioning to use the Twilio plugin which I am unless you are talking about another Mautic-Twilio plugin that I’m not aware off. In the previous configuration with that php script I was using the Twilio plugin. Have you used Ubuntu before? That white screen issue is a tough one, maybe .htaccess related or cache issues? Thanks

Sorry my previous host was Web Hosting Canada, bad tech support, so I moved on to Ionos with VPS.

I’m also pasting the message from my previous host Web Hosting Canada:

Furthermore, I have checked the forum “Cronjob not working on mautic 3.0.1 - #6 by stefanomarty” that you have provided and noticed that the cron jobs were setup at the root of the server. Please note that your account is hosted on a shared hosting server and because of this, it is not possible to setup cron at the root directory. You have to go with Cloud OR dedicated server to perfrom this root task: Managed Canadian Cloud Servers - Web Hosting Canada || Canadian Dedicated Servers - Web Hosting Canada

Install Mautic via CLI, its much easier and less error prone. Twili plugin ships with the core.