Mandrill's attachment without extension on Hotmail/Outlook.com - php

I guess there is a issue with Mandrill attachments x Hotmail/Outlook.com.
I can send e-mail attachments with Mandrill using base64_encode(). I am using the PHP library.
If I send an e-mail to Gmail or any other provider, the attachment looks fine. Downloading it and opening normally.
But sending to a Hotmail/Outlook.com, the attachments came with no extension/file format. By downloading, it can only be opened by adding the extension manually (for example, .pdf).
The code:
$file_data = file_get_contents($_FILES["test_file"]["tmp_name"])
$file_type = $_FILES["test_file"]["type"]
$mandrill = new Mandrill('MANDRILL_API_KEY_HERE');
$message = array(
'html' => $html,
'subject' => 'Testing',
'from_email' => 'sender#test.com',
'from_name' => 'Sender',
'attachments' => array(
array(
'name' => 'Test PDF document',
'type' => $file_type,
'content' => base64_encode($file_data)
)
),
'to' => array(
array(
'email' => 'to#test.com',
'name' => 'John Doe',
'type' => 'to'
)
),
'headers' => array('Reply-To' => 'sender#test.com')
);
$result = $mandrill->messages->send($message);
Any ideas? Is it a Mandrill or Hotmail issue?
Thanks!

I have found the solution. Gmail and other email services recognizes the type attribute as above, but Hotmail only recognizes the file type by adding the extension to the attachment name (name attribute).
For example:
'name' => 'Test PDF document.pdf',
It look obvious, but Hotmail requires it. Sharing my simple knowledge, since I received no answers.

Related

Mandrill not showing the right Cc information

This issue really driving me crazy this past hours. Why is the email that send with Mandrill not showing the right information about the Cc email address.
So for example, I want to send email to
receiver_to_a#mail.com
receiver_cc_a#mail.com
receiver_cc_b#mail.com
When I see the email header on receiver_cc_a#mail.com. its always show no cc, and that email is send "to" receiver_cc_a#mail.com, not as cc
Is anyone having the same problem? I already try sending email in PHP with PhpMailer and also try from the PHP API from Mandrill itself but no luck.
You need to set the option preserve_recipients to true.
$message = array(
'html' => '<p>Example HTML content</p>',
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => 'message.from_email#example.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
),
array(
'email' => 'ccrecipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'cc'
)
),
'headers' => array('Reply-To' => 'message.reply#example.com'),
'preserve_recipients' => true
);

Overwrite issue in merge_vars of Mandrill API

I am sending email using merge_vars for dynamic contents. Here is how my merge_vars look like:
$message['merge_vars'][$index] = array(
'rcpt' => $email,
'vars' => array(
array(
'name' => 'url',
'content' => $url
),
array(
'name' => 'sname',
'content' => $sname
),
array(
'name' => 'lname',
'content' => $lname,
),
array(
'name' => 'email',
'content' => $email
)
),
);
Everything is working fine. But when same recipient should receive multiple different email in a single API call, then the problem occurs. That time same recipient don't receive different email, he receives same email multiple times.
In a single api call you cannot send different emails to same email address with different merge vars.
You need to fire multiple api calls having target recipient in each call with respective merge_vars to meet your requirement.

sending email using zend/mail

I want to send an email using zend/mail in zend framework 2.
I already have some code but i don't know where to put it, and also not how to trigger this.
$mail = new Mail\Message();
$mail->setBody('This is the text of the email.');
$mail->setFrom('email#hotmail.be', 'email');
$mail->addTo('email#hotmail.be', 'email');
$mail->setSubject('Dit is een email verzonden van de computer');
$transport = new Mail\Transport\Sendmail('-freturn_to_email#hotmail.be');
$transport->send($mail);
I still new at Zend framework 2.
Can anybody help me with this?
I would advice you to take a look at Soflomo\Mail. Note, I am the author of Soflomo mail, but it helps you a lot with sending mails. It eases the config and dependency hassle.
Put "soflomo/mail": "~0.3" in your composer.json file and run the following command:
php composer.phar update soflomo/mail
Next, enable the module Soflomo\Mail in your application.config.php. When you use Zend\Mvc, you will have a controller/action which should trigger the email. For the most simplified use case, you can do this:
public function doAction()
{
// some of your logic
$service = $this->getServiceLocator()->get('Soflomo\Mail\Service\MailService');
$service->send(array(
'to' => 'email#hotmail.be',
'to_name' => 'email',
'from' => 'email#hotmail.be',
'from_name' => 'email',
'subject' => 'Dit is een email verzonden van de computer',
'template' => 'mail/message/default'
));
}
Now Soflomo\Mail sends a message by rendering a template and use that as message text. Here I defined a message mail/message/default so create that file (e.g. module/Application/view/mail/message/default.phtml) with this content:
This is the text of the email.
The last thing to do is to configure how Soflomo/Mail sends the message. Your question uses Sendmail, so I am using this as well in this example. Create a configuration file in config/autoload , e.g. config/autoload/soflomo_mail.global.php which contains the following content:
return array(
'soflomo_mail' => array(
'transport' => array(
'type' => 'sendmail',
),
),
);
If you want to switch to e.g. GMail as transport layer, replace above config with:
return array(
'soflomo_mail' => array(
'transport' => array(
'type' => 'smtp',
'options' => array(
'name' => 'gmail.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
),
),
'variables' => array(
'username' => '',
'password' => '',
),
),
),
);
And create a new file config/autoload/soflomo_mail.local.php:
return array(
'soflomo_mail' => array(
'transport' => array(
'variables' => array(
'username' => 'my-address#gmail.com',
'password' => '1234secure7890',
),
),
),
);
I guess Hotmail would be similar to GMail.
You can use this within the zend directory,
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('somebody#example.com', 'Some Sender');
$mail->addTo('somebody_else#example.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send();

Sending email with Mandrill using PHP

I'm trying to send email using Mandrill and PHP and I can't get it to send.
I've downloaded the PHP API wrapper from here:https://packagist.org/packages/mandrill/mandrill
Mandrill.php is in my root and the Mandrill folder is in the same directory.
Here's my code:
<?php
require_once 'Mandrill.php';
$mandrill = new Mandrill('MY API KEY IS USUALLY HERE');
$message = array(
'subject' => 'Test message',
'from_email' => 'jwjody#yahoo.com',
'from_name' => 'Sender person',
'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
'to' => array(array('email' => 'jwjody#yahoo.com', 'name' => 'Recipient 1')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#domain.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Recipient 1 first name'),
array(
'name' => 'LASTNAME',
'content' => 'Last name')
))));
//print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
echo ("hello");
?>
But it won't send. I'm not sure where the failure is. Is it something obvious I'm missing?
I see the issue now.
I see what's going on now!
I changed
$mandrill->messages->sendTemplate($template_name, $template_content, $message));
to
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);
And it works!
Instead of calling the sendTemplate() function I should have used
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);
Once I changed the function call the mail was sent.

Mandrill and PHP not sending transactional email out

So I've made a template called 'Basic' within Mandrill. I did a test send and it looks great. I put Mandrill into test mode and used the test API key in my code. I'm just trying to get the php to send out a test transactional email, but no email gets sent. Here is the printed response I get:
Array ( [0] => Array ( [email] => amiecrutchley02#gmail.com [status] => sent [_id] => 89bfab4c3938486eb9e36564f79a3e9f [reject_reason] => ) )
So I'm really not sure why I'm not receiving anything.
Here is my code:
<?php
require_once('includes/mandrill/Mandrill.php');
$mandrill = new Mandrill('my_api_key');
$message = array(
'subject' => 'Thank You For Your Purchase',
'from_email' => 'no-reply#acq.com',
'from_name' => 'ACQ',
'to' => array(array('email' => 'amiecrutchley02#gmail.com', 'name' => 'Amie')),
'merge_vars' => array(array(
'rcpt' => 'amiecrutchley02#gmail.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Amie'),
array(
'name' => 'LASTNAME',
'content' => 'Crutchley')
))));
$template_name = 'Basic';
$template_content = array(
array(
'name' => 'main',
'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, your profile has been updated!'),
array(
'name' => 'footer',
'content' => 'ACQ, Copyright 2014')
);
$response = $mandrill->messages->sendTemplate($template_name, $template_content, $message);
print_r($response);
?>
a test API key is specifically designed to not send email. It's designed so you can mimic sending email, but doesn't actually send. You're also not charged for sending tests. Here's the Mandrill KB about what test mode is, and how it works: Does Mandrill have a test mode or sandbox?
Well, weird, but my test API was the problem. I tried the public API and boom! It works!

Categories