propiedad para mail formulario enviar correos correo configurar con codigo php mailchimp mandrill

para - enviar formulario a correo php



Simple función php para enviar un correo electrónico con Mandrill. (5)

Cuál es la forma más fácil de enviar un correo electrónico a través del servicio Mandrill de Mailchimp (usando la API).

Aquí está el método de envío: https://mandrillapp.com/api/docs/messages.html#method=send

Aquí está el contenedor de API: https://bitbucket.org/mailchimp/mandrill-api-php/src/fe07e22a703314a51f1ab0804018ed32286a9504/src?at=master

Pero no puedo averiguar cómo hacer una función de PHP que se envíe y envíe por correo electrónico a través de Mandrill.

¿Alguien puede ayudar?


Esta es la pieza de código más básica que podría darle, solo la elaboré hace unos segundos para un cliente y está funcionando sin problemas.

require_once ''path/to/your/mandrill/file/Mandrill.php''; try { $mandrill = new Mandrill(''your-API-key''); $message = array( ''html'' => $htmlMessage, ''subject'' => $subject, ''from_email'' => $fromEmail, ''from_name'' => $fromName, ''to'' => array( array( ''email'' => $toEmail, ''name'' => $toName, ''type'' => ''to'' ) ) ); $result = $mandrill->messages->send($message); print_r($result); } catch(Mandrill_Error $e) { echo ''A mandrill error occurred: '' . get_class($e) . '' - '' . $e->getMessage(); throw $e; }

También revise su método de envío para ver más opciones como encabezados, metadatos, archivos adjuntos, etc. https://mandrillapp.com/api/docs/messages.php.html#method-send



Mandrill toma las POST HTTP POST para todos sus métodos de API, y ellos toman su entrada como una cadena JSON. Aquí hay un ejemplo básico de enviar un correo electrónico. Utiliza cURL para hacer la solicitud HTTP:

$uri = ''https://mandrillapp.com/api/1.0/messages/send.json''; $postString = ''{ "key": "YOUR KEY HERE", "message": { "html": "this is the emails html content", "text": "this is the emails text content", "subject": "this is the subject", "from_email": "[email protected]", "from_name": "John", "to": [ { "email": "[email protected]", "name": "Bob" } ], "headers": { }, "track_opens": true, "track_clicks": true, "auto_text": true, "url_strip_qs": true, "preserve_recipients": true, "merge": true, "global_merge_vars": [ ], "merge_vars": [ ], "tags": [ ], "google_analytics_domains": [ ], "google_analytics_campaign": "...", "metadata": [ ], "recipient_metadata": [ ], "attachments": [ ] }, "async": false }''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); $result = curl_exec($ch); echo $result;


También tenemos un contenedor de API oficial para PHP, que está disponible en Bitbucket o por medio de Packagist , que envuelve la API de Mandrill para usted.

Si su clave API de Mandrill se almacena como una variable de entorno, aquí hay un ejemplo simple de envío mediante una plantilla, con algunas variables de fusión y metadatos:

<?php require ''Mandrill.php''; $mandrill = new Mandrill(); // If are not using environment variables to specific your API key, use: // $mandrill = new Mandrill("YOUR_API_KEY") $message = array( ''subject'' => ''Test message'', ''from_email'' => ''[email protected]'', ''html'' => ''<p>this is a test message with Mandrill/'s PHP wrapper!.</p>'', ''to'' => array(array(''email'' => ''[email protected]'', ''name'' => ''Recipient 1'')), ''merge_vars'' => array(array( ''rcpt'' => ''[email protected]'', ''vars'' => array( array( ''name'' => ''FIRSTNAME'', ''content'' => ''Recipient 1 first name''), array( ''name'' => ''LASTNAME'', ''content'' => ''Last name'') )))); $template_name = ''Stationary''; $template_content = array( array( ''name'' => ''main'', ''content'' => ''Hi *|FIRSTNAME|* *|LASTNAME|*, thanks for signing up.''), array( ''name'' => ''footer'', ''content'' => ''Copyright 2012.'') ); print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message)); ?>


// Simply Send Email Via Mandrill... require_once ''Mandrill.php''; $mandrill = new Mandrill($apikey); $message = new stdClass(); $message->html = "html message"; $message->text = "text body"; $message->subject = "email subject"; $message->from_email = "[email protected]"; $message->from_name = "From Name"; $message->to = array(array("email" => "[email protected]")); $message->track_opens = true; $response = $mandrill->messages->send($message);