Your software
My Mautic version is: v4.4.6
My PHP version is: 8.0.27
My Database type and version is: 10.5.19-MariaDB-0+deb11u2
Your problem
My problem is:
I am trying to use a variable in a href of a button, but it just redirects me to a 404.
The way I was doing the integration is as follows: GET DETAILS
The button has to have the url that is sent from the form as a custom field to send it to a specific url, the data arrives to mautic correctly, the variables in the mail work fine, the problem is the variable in the href.
The data I get from the form arrives well to Mautic, in the email code that should reach the customer after filling out the form is the one that has the problem that the variable does not take the value of the url and sends to a 404.
The data arrives well from the form as attached above, the problem is in the variable inserted in the href of the <a> tag of the mail that I send as a response after filling out the form, mautic removes the variable and redirects to an internal URL 404 or if I put the variable in a <p> tag shows it only as text, it means that the variable is displayed, only in the href does not work and is not clickable.
Also do the test by passing a URL type variable to the href or only a text type variable only with the part of the search that I want it to redirect to leaving the rest of the URL defined, but it still doesn’t work, mautic changes those URLs to those of the domain and redirecting to a 404 as you said above.
Here are some examples of how I’m implementing it: <a style="text-decoration: none; margin: 0;" href="{contactfield=support_general_href}"><span style="color: #c71618;">GET DETAILS <br></span></a>
This one here has been tried with the development URL or with a production URL, so they are validated URLs: <a style="text-decoration: none; margin: 0;" href="http://domain-sandbox.s3-website.us-east-2.amazonaws.com/EN/general_support.html?message={contactfield=general_support}"><span style="color: #c71618 ;">GET DETAILS <br/></span></a>
This is how it works, it displays the variable, in this case the URL, but it’s not clickable, it just displays as text. <p>url: {contactfield=support_general_href}</p>
Could you maybe test with a text field instead of an URL field?
Just a gut feeling… what you replace in your html is a string. Maybe the URL formatted field may be the issue?
@aantonio.tech I know this is a bit late but I ran into a similar issue today where my contactfield variables were showing in my email body but disappearing when included in an href.
In my case, I was referring to my variables in camelcase, and this worked: <p>{contactfield=customUnsubscribeLink}</p>
But <a href="{contactfield=customUnsubscribeLink}">Unsubscribe</a> failed. The solution in my case was using the correct lower alias in the href, <a href="{contactfield=customunsubscribelink}">Unsubscribe</a>.
In your screenshots it looked like you were doing snake_case variables so not sure if this is the same issue. It does seem like Mautic uses a tighter set of rules for variables in href tags compared to the rest of the email body.
Thank you very much, I tried another approach to the problem that did not involve Mautic, but I am going to do it with Mautic to see if that is a bug and report it as such.
Hi, I would like to know ho did you add the customer unsubscribe link as one of the contact field, I did try to add a custom field but not able to add any URL To it.
I was planning to create something {contactfield=customUnsubscribeLink} like this, is this just a normal custom fields? and if so how is it able to unsub a customer.
@jichodalen In our case we created a custom field of “URL” data type. We have a unique setup where we’re unsubscribing people through our own server (which also sends some direct email, not via Mautic). As part of our process we call Mautic via REST API to complete the Mautic-side unsubscribes.
We’re using javascript to encode the user’s email address as part of that “1-click unsubscribe link”, so the customUnsubscribeLink field has a different value for each user such as https://domain.com/unsubscribe?email=firstlast%2B715%40gmail.com. User clicks and gets a “You’ve been unsubscribed” message from our server, which removes the user all lists (Mautic and non-Mautic). Your requirements might be different, hope this example helps!
My example might have been unclear. If you’re working in Javascript, you’ll want to call encodeURIComponent() on the email so it’s encoded as a parameter. For example, encodeURIComponent(“firstlast@gmail.com”) results in firstlast%40gmail.com.