I use mailgun and integrated with php. The mail sends fine without error. I create a default template in mailgun(Action Template). In that template there is a button. My Issue is
How to i pass a parameter to that button a tag
MY code is
$mg = Mailgun::create('MY API');
// Now, compose and send your message.
$result = $mg->messages()->send('MY DOMAIN NAME', [
'from' => 'support#figjam.net',
'to' => $email,
'subject' => 'Confirm Your E-mail',
'html' => ' <p>Please confirm your email address by click the link below <br>
<button type="button" class="btn btn-secondary">CLICK TO ACTIVATE YOUR ACCOUNT</button></p>'
'template' => 'verifyemail'
]);
I need to pass variable to that template verifyemail
Kindly Help me fix this.
Thanks
Let's assume you have myvariable with value someVariableValue
'template' => 'verifyemail',
'v:myvariable' => 'someVariableValue',
]);
Related
I am trying to pass multiple images via Mailgun's inline API-parameter. I have no problem with only one image, but when I try with multiple images - as in the code below - only the last image in the array is displayed in the email.
$template = View::make('emails.template')->render();
$result = $mgClient->sendMessage($domain, array(
'from' => $sender,
'to' => implode(',',$emailAddresses),
'subject' => '%recipient.subject%',
'text' => $messageText,
'recipient-variables' => json_encode($credentials),
'html' => $template
), array(
'inline' => array(
'path/to/image1.png',
'path/to/image2.png',
'path/to/image3.png',
'path/to/image4.png')
));
The code above works as if the last element in the array is the only element.
The documentation for sending inline images with Mailgun is found here and it's said here that "You can post multiple inline values" which means that I'm definitely doing something wrong.
Try this once:
$result = $mgClient->sendMessage($domain, array(
'from' => $sender,
'to' => implode(',',$emailAddresses),
'subject' => '%recipient.subject%',
'text' => $messageText,
'recipient-variables' => json_encode($credentials),
'html' => $template
), array(
'inline' => array(
array('path/to/image1.png'),
array('path/to/image2.png'),
array('path/to/image3.png'),
array('path/to/image4.png')
)));
Basically wrapping each image path in an array.
Also what is the contents of $template?
This was actually a recently introduced bug. A new pull request has been submitted to the official Mailgun PHP SDK, for more info see here.
So to answer the question: the code is working fine, as soon as the SDK is updated according to above pull request. For now I edited my local copy of mailgun-php accordingly and it worked fine. Many thanks to Travis Swientek on Mailgun for quick response.
How I can use variables in mailgun?
In the test email (test#example.com) I added the following variable
{"age": 20}
but it does not go as is used when creating the mail.
Here goes the code when the mail is sent.
$mailformat = "CODE HTML :D";
$result = $mgClient->sendMessage($domain, array(
'from' => 'Example <example#example.com>',
'to' => 'test#example.com',
'subject' => '%recipient_fname%, testing mail',
'html' => $mailformat
));
You should add the user variables this way:
v:age=20
If you're using Python, in the data element you must add
data={
'from' : 'Name <email#email>',
'to' : email_list,
...
'v:age' : '20'
}
From the documentation:
v: prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See Attaching Data to Messages for more information.
I have the following code:
Mail::send('emails.welcome', $data, function($message) use ($user){
$message->from('xxx#xxx.xxx', 'XXXXX');
$message->to($user['email'], $user['name'])->subject('Welcome to My Laravel app!');
});
Now, it doesn't matter what I put in the email template (emails.welcome) the email message is always blank!
Does anyone have any idea why this is happening?
go to app/config/mail.php
in line 57
'from' => array('address' => null, 'name' => null),
set the value for the address and name
I'm trying to send a Mandrill email in the default Laravel 4 Mailer, and I want to set the template and send the data to Mandrill. I'd rather not use a local file in my Laravel, I have this all set up to work inside of Mandrill. This is how I have it set in Laravel:
Mail::send('emails.test',[],function($message)
{
$message->to(Input::get('email'), 'John Smith')->subject('Welcome!');
});
return
This sends an email from my "test" view inside of "emails" like it should. In vanilla PHP using the Mandrill library this would work to send to the template I want.
$message = array(
'subject' => 'Subject redacted',
'from_email' => $main_email,
'to' => array(array('email' => $to_email)),
'merge_vars' => array(array(
'rcpt' => $to_email,
'vars' =>
array(
array(
'name' => 'DETAIL',
'content' => $detail),
array(
'name' => 'ERROR_AMOUNT',
'content' => '$'.$trans_amount)
,
array(
'name' => 'CO_NAME',
'content' => $business_name),
array(
'name' => 'SMS',
'content' => $sms)
))));
$template_name = 'Test Email';
$template_content = array(
array(
'name' => 'main',
)
);
$response = $mandrill->messages->sendTemplate($template_name, $template_content, $message);
As an alternative, you could set the X-MC-MergeVars and X-MC-Template headers using Laravel's Mandrill functions.
Mail::send('emails.test', [], function($message) use ($mergevars)
{
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-MergeVars', json_encode($mergevars));
$headers->addTextHeader('X-MC-Template', 'my-template');
$message->to(Input::get('email'), 'John Smith')->subject('Welcome!');
});
Note that I haven't tested this - just going by what I read here: Using SMTP Headers to customize your messages.
You might need to use something other than addTextHeader - check with the Swiftmailer documentation to work out how to add the correct header type for the data you are setting.
It doesn't appear that this is possible using Illuminate\Mail\Mailer. It looks like the Mandrill transport specifically uses the send-raw Mandrill API endpoint.
This leaves you with two options: Implement your own transport and work within the Mailer, or work outside the Mailer system. If you're going to go with the latter, you'd probably be best off just using the official library.
If you want to implement your own transport, take a look at the Swift_Transport interface. It's not going to be a perfect match, since you're attempting to do something that the Mailer was never intended to do, but with enough hacking, you could get something up and running. You'd probably need to use undefined members on the Message class, like:
$message->template = "template_name";
$message->content = array(/* content here */);
$message->message = array(/* message here */);
// MandrilTemplateTransport.php
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$this->messages->send($message->template, $message->content, $message->message);
}
This is absolutely less than ideal, but a workable solution. I'd vote that you just use the Mandrill library outside of the Mailer system.
I write Simple code for contqact Form,which contain fields name, email and message. I want to write test cases for it to check user enter fields value are match with the expected value or not. But i m not getting user enter value while I execute 'contactTest.php' file using command "./symfony test:functional frontend contact"
Code:
enter code here
<?php
include('/home/APP/test/bootstrap/functional.php');
$browser = new sfTestFunctional(new sfBrowser());
$browser->
get('/Contact/thankyou')->
with('request')->begin()->
isParameter('module', 'Contact')->
isParameter('action', 'thankyou')->
end();
$browser->
get('/Contact/index')->
click('Submit', array(
'name' => 'Test',
'email' => 'not.an.email',
'message' => 'message'
))->
isRedirected()->
followRedirect()->
with('response')->checkElement('#content ul li','Testa');
get('/Contact/thankyou', array('name' => 'Test'));
?>
Please help me to write testcase for checking user enter value in the form and expected value. And also suggest how to run & test?
It looks to me that you forgot to provide your form object.
Can you share your form template?
You probably want something like this :
get('/Contact/index')->
click('Submit', array(
contact => array(
'name' => 'Test',
'email' => 'not.an.email',
'message' => 'message'
)
))->