I am trying to send mail in symfony with attachment with the help of mailgun
I have referred this Question. And this Reference. But didn't helped me.
This is my function,
public function sendMail($to, $subject, $body, $attachment = null)
{
$mgClient = new Mailgun($this->container->getParameter('mailgun_key'));
$domain = $this->container->getParameter('mailgun_domain');
$content = [
'from' => $this->container->getParameter('mailgun_from'),
'to' => 'tester <' . $to . '>',
'subject' => $subject,
'text' => $body
];
if (!empty($attachment)) {
$result = $mgClient->sendMessage("$domain", $content);
} else {
$result = $mgClient->sendMessage("$domain", $content, [
'attachment[0]' => [$attachment]
]);
}
return $result;
}
In attachment, I'm passing the file path. i.e /home/mypc/Downloads/test.txt
But I'm receiving only blank mail. Attachment is not coming.
Where am I wrong? Please help.