Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
mailgun - enviar correo con archivo adjunto

Estoy tratando de enviar un correo en Symfony con un archivo adjunto con la ayuda de mailgun

He referido esta pregunta . Y esta Referencia . Pero no me ayudó.

Esta es mi función,

 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; }

En el archivo adjunto, paso la ruta del archivo. es decir /home/mypc/Downloads/test.txt

Pero solo recibo correo en blanco. El archivo adjunto no viene.

¿Dónde estoy equivocado? Por favor ayuda.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

La documentación de archivos adjuntos de pistola de correo tiene la siguiente información:

Archivos adjuntos

Puede adjuntar un archivo desde la memoria o mediante una ruta de archivo.

Desde la ruta del archivo

 $mg->messages()->send('example.com', [ 'from' => 'bob@example.com', 'to' => 'sally@example.com', 'subject' => 'Test file path attachments', 'text' => 'Test', 'attachment' => [ ['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg'] ] ]);

De memoria

 // Some how load the file to memory $binaryFile = '[Binary data]'; $mg->messages()->send('example.com', [ 'from' => 'bob@example.com', 'to' => 'sally@example.com', 'subject' => 'Test memory attachments', 'text' => 'Test', 'attachment' => [ ['fileContent'=>$binaryFile, 'filename'=>'test.jpg'] ] ]);

Archivos adjuntos en línea

 $mg->messages()->send('example.com', [ 'from' => 'bob@example.com', 'to' => 'sally@example.com', 'subject' => 'Test inline attachments', 'text' => 'Test', 'inline' => [ ['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg'] ] ]);
about 4 years ago · Santiago Trujillo Denunciar

0

Reemplace el código a continuación

 $result = $mgClient->sendMessage("$domain", $content, [ 'attachment[0]' => [$attachment] ]);

Con

 $result = $mgClient->sendMessage("$domain", $content, array( 'attachment' => array($attachment) ));

P.ej.

 $result = $mgClient->sendMessage("$domain", $content, array( 'attachment' => array('/home/mypc/Downloads/test.txt') ));

Referencia: https://documentation.mailgun.com/user_manual.html#sending-via-api

about 4 years ago · Santiago Trujillo Denunciar

0

El siguiente ejemplo funciona para mí.

Prueba

 $mgClient = new Mailgun('key-abcfdfa5b40b6ea0ec0ccf9c33a90y65'); $domain = "sandbox111df299cae04a3ea77733f374b73oi8.mailgun.org"; // SEND $result = $mgClient->sendMessage( $domain, [ 'from' => 'Sender <mailgun@sandbox111df299cae04a3ea77733f374b73oi8.mailgun.org>', 'to' => 'Receiver <bentcoder@sandbox111df299cae04a3ea77733f374b73oi8.mailgun.org>', 'subject' => 'Test subject', 'text' => 'Test message body', ], [ 'attachment' => [ '/var/www/html/local/test_app/logo.jpg', '/var/www/html/local/test_app/ngrok.png' ] ] ); // END print_r($result); stdClass Object ( [http_response_body] => stdClass Object ( [id] => [message] => Queued. Thank you. ) [http_response_code] => 200 )

También puede buscar en https://github.com/tehplague/swiftmailer-mailgun-bundle .

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda