app php mailgun

php - app mailgun



¿Cómo enviar un correo electrónico HTML con mailgun? (2)

Añadiendo un enlace a la documentación de Mailgun. Esto me ayudó mientras construía mensajes HTML y MIME. https://documentation.mailgun.com/api-sending.html#examples

Según la documentación:

# Include the Autoloader (see "Libraries" for install instructions) require ''vendor/autoload.php''; use Mailgun/Mailgun; # Instantiate the client. $mgClient = new Mailgun(''YOUR_API_KEY''); $domain = "YOUR_DOMAIN_NAME"; # Make the call to the client. $result = $mgClient->sendMessage($domain, array( ''from'' => ''Excited User <YOU@YOUR_DOMAIN_NAME>'', ''to'' => ''[email protected]'', ''cc'' => ''[email protected]'', ''bcc'' => ''[email protected]'', ''subject'' => ''Hello'', ''text'' => ''Testing some Mailgun awesomness!'', ''html'' => ''<html>HTML version of the body</html>'' ), array( ''attachment'' => array(''/path/to/file.txt'', ''/path/to/file.txt'') ));

Después de que no encontré una solución para mi problema en la documentación de mailgun, explicaré lo que estoy buscando.

Hoy estoy usando phpList para enviar mi boletín de noticias (¡Funciona perfecto!), Tengo páginas HTML que acabo de incluir en la aplicación phpList para enviarlas. (Estoy usando el método SMTP para enviar noticias). Me pregunto si puedo hacer lo mismo con mailgun (seguro que sí, pero ¿cómo?) ¿Es posible incluir la ruta de mis páginas HTML para enviarla? (No tengo interés en escribir mi código html en el script, debe estar en la ruta, de lo contrario no tengo ningún interés en usar mailgun).

Eche un vistazo a mi código php de mailgun de la siguiente manera:

$result = $mgClient->sendMessage("$domain", array(''from'' => ''My Business Name <[email protected]>'', ''to'' => ''[email protected], [email protected], [email protected]'', ''subject'' => ''Issue Feb 2014'', ''text'' => ''Your mail do not support HTML'', ''html'' => ''<html>Inline image: <img src="cid:Pad-Thai-1.jpg"></html>'', ''recipient-variables'' => ''{"[email protected]": {"first":"Name-1", "id":1}, "[email protected]": {"first":"Name-2", "id": 2}}''), array(''inline'' => ''Pad-Thai-1.jpg''));

Tengo el elemento del arreglo llamado ''html'' , me gustaría incluir la ruta de mi página HTML (si no es posible, ¿dónde puedo ubicarlo?). Simplemente no puedo incluir todo mi código HTML en este elemento de matriz html, porque es muy extenso.

Pero el correo electrónico dice ser fácil y genial, ese es el motivo que quiero cambiar.


He utilizado la plantilla html externa de esta manera. Puede ser de ayuda.

$html = file_get_contents(''my_template.html''); // this will retrieve the html document

y entonces:

$result = $mgClient->sendMessage("$domain", array(''from'' => ''My Business Name <[email protected]>'', ''to'' => ''[email protected], [email protected], [email protected]'', ''subject'' => ''Issue Feb 2014'', ''text'' => ''Your mail do not support HTML'', ''html'' => $html, ''recipient-variables'' => ''{"[email protected]": {"first":"Name-1", "id":1}, "[email protected]": {"first":"Name-2", "id": 2}}''), array(''inline'' => ''Pad-Thai-1.jpg''));

Compruebe esta línea:

''html'' => $html,