mandrill template '#' stripped out from email address - mandrill

I'm using the Mandrill API to send html email. I have a link in my template that contains a query string with an email address, however the '#' sign is stripped out when receiving the email.
I'm using global_merge_vars thus:
'global_merge_vars' => array(
array(
'name' => 'merge1',
'content' => 'merge1 content'
),
array(
'name' => 'UEMAIL',
'content' => $uEmail
)
),
Example of the link:
http://www.test.com/?email=test#test.com
is received as
http://www.test.com/?email=testtest.com
How can I prevent the '#' from being stripped out?
Thanks!

You have to encode your url because the # sign is special character.

You'll need to URL encode the email address parameter before passing it to Mandrill.
It looks like you're writing in PHP? Try the urlencode function.

Related

escape comma in ruby URI::HTTP library

I'm using URI::HTTP library to build a URL I need to use to send to an endpoint.
ids = "12345,54504"
uri = URI::HTTP.build({
:host => HOST,
:path => '/endpoint',
:query => {
:ids => ids
}.to_query,
})
The issue I am having is that the endpoint is expecting ids to be comma-separated. However, the URL that this builds replaces the comma with %2C. How do I get the url to just send the comma and not encode it.
Don't worry the %2C is the URL-encoded of the comma.
You can try to create a route in your rails application and puts params[:ids], you will see your ids with the coma.

ZF2 - Formatting Routes

I typically format my routes in ZF2 like so: /name/to/route
Now I have been doing the same thing with my api routes however I am finding that I am struggling to include data such as encoded urls or arrays.
Here is an example of such a route:
http://example.com/api/register/access/code/c102dea422fa4bb6958d77a29d9873d2/http%3A%2F%2Frouter-local.example.com%2Fapi%2Fdirectory
The following represents forward slashes and thus causes the route not to work: %3A%2F%2
I am thinking I should encode my route as such:
http://example.com/api/register/access/code/?access_code=c102dea422fa4bb6958d77a29d9873d2&route=http%3A%2F%example.com%2Fapi%2Fdirectory
How do you configure the module.config file to deal with this?
Currently it is set as such in apigility:
'api.rpc.register-access-code' => array(
'type' => 'Segment',
'options' => array(
'route' => '/api/register/access/code/:access_code/:route',
'defaults' => array(
'controller' => 'Api\\V1\\Rpc\\RegisterAccessCode\\Controller',
'action' => 'registerAccessCode',
),
),
),
EDIT
I have encoded my routes to include GET parameters by doing the following:
$url = "http://example.com/api/register/access/code/";
$params = [
'access_code' => 'c102dea422fa4bb6958d77a29d9873d2',
'route' => 'http://example.com/api/directory'
];
$final = $url . "?" . http_build_query($params);
Which gives this:
http://example.com/api/register/access/code/?access_code=c102dea422fa4bb6958d77a29d9873d2&route=http%3A%2F%2Fexample.com%2Fapi%2Fdirectory
However this breaks due to a "The requested URL could not be matched by routing." error.
The route is unidentified due to the interpretation of the slashes in the included URL.
Perhaps the issue is to do with how the URL is formatted and included as a parameter?
You don't define query variables in the segment route option; only the path.
You may append ?query=vars to any url, regardless of route configuration. ZF2's url helpers should encode the query vars for you, you just have to create an array of query vars and give it to the helper function when creating a url.
<?php echo $this->url('api.rpc.register-access-code', array(), array('query' => array(
'access_code' => 'c102dea422fa4bb6958d77a29d9873d2',
'route' => 'http://router-local.example.com/api/directory',
))); ?>`
In this case, it would seem the problem is to do with htaccess or apache. The simplest solution has been to encode the url using: base64_encode($url) which can be de-coded at the other end.

How to get an array of values for the router "segment"?

I use a form with a multiupload. My addAction save information regarding the downloaded files in the database, and obtains an array lastInsrtId() values. If the upload was successful, I need to be redirected to editAction, where a user can see a list of downloaded files and user can edit file attributes such as title, description and alt attribute for images for each downloaded file using this files list. How do I pass an array of values ​​in the route? Here is my code addAction:
// upload success
$fileIds = $this->getContentService()->makeFiles($parent, $data);
return $this->redirect()->toRoute('sc-admin/file/edit', array('ids' => $fileIds));
Here is the definition for a route that should display a list of files for editing:
'edit' => array(
'type' => 'segment',
'options' => array(
'route' => '/edit[/:ids]',
'defaults' => array(
'controller' => 'sc-file',
'action' => 'edit',
),
),
),
But it generates an error for editAction
rawurlencode() expects parameter 1 to be string, array given
I do not want to use the session whenever the parameters necessary to pass an array of values, because it is a matter solely routing.
Ever seen this url?
http://foo.bar/baz?array(1=>2,3=>4)
Probably not. You got an error message so do as the error message says. This has nothing to do with Zend Framework, this is basic PHP (too many people often forget what's the core...).
array('ids' => serialize($data))
See php:serialize() and php:unserialize()

Drupal: $_POST and MENU_CALLBACK. How works?

i've read this ad this but nothing is working for me
I'd like to create a menu like this
$items['login'] = array(
'page callback' => 'mymodule_login',
'access arguments' => array('access content'),
'access callback' => true,
'type' => MENU_CALLBACK,
);
in order to send a POST to http://www.example.com/login. The body contains a json with username e password. Everything is ok, except for $_POST under function mymodule_login that does not works. $_POST is empty. What's wrong? Is there another "drupalic" way?
Try this:
$data = file_get_contents("php://input");
Or make sure your form url using trailing slash:
<form action="login/" method="post">

ZF2 Route with Colon Separator

I am working with ZF2 and trying to setup Route configuration that uses a colon separator.
For example, the web address could be www.example.com/namespace:subject and I want to send it to a specific controller, action with the two variables. I am trying to use a Regex since the colon ":" is a special character for segments. Is there a nice way to do this? Here is my route configuration:
'dataReqs' => array(
'type' => 'regex',
'options' => array(
'regex' => '/(?<namespace>[^:]+).(?<subject>[a-zA-Z0-9_-]+)',
'defaults' => array(
'controller' => 'Application\Controller\Data',
'action' => 'get',
),
'spec' => '/%namespace%:%subject%',
),
),
EDIT: I want to use the colon as the prefix:resource format is commonly used in RDF syntax (http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/#QSynIRI). For instance, a long uri like http://dbpedia.org/data/Semantic_Web with a #prefix dbp: http://dbpedia.org/resource/ may be referred in a document with dbp:Semantic_Web. So for my Linked Data server I could direct requests and include the prefix (namespace) and the resource name; eg http://myserver.com/dbp:Semantic_Web. While I am using the segment combinations /namespace/resource for now, it would be nice to handle a route with prefix:resource syntax.
Do not use colon in your route. It isn't good practice, because colon is reserved character(see https://www.rfc-editor.org/rfc/rfc3986#section-2.2)
I'm inclined to agree with kormik. Why do you want to specify URL's in that way? What is wrong with the default behavior?
www.example.com/namespace/subject
eg:
www.example.com/somenamespace/10
or even:
www.exmple.com/namespace/namespace/subject/subject
eg
www.example.com/namespace/somenamespace/subject/10
you can easily grab these parameters in the controller like so:
$ns = $this->params()->fromRoute('namespace',0);
$subject = (int) $this->params->fromRoute('subject',0);
You would need to modify the route config also.

Resources