Search code examples
phpformsemailmailgun

How to send mailgun email from form?


I would like to use a form to send a verification email though mailgun to users when they sign up for a service. I have a form collecting the required info for the email but need to put it into the email. The problem is the way the email is formatted and I do not know how to print the data.

Here is my action:

<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;

$mgClient = new Mailgun('MY-API-KEY');
$domain =     "https://api.mailgun.net/v3/MY-DOMAIN";

$result = $mgClient->sendMessage($domain, array(
'from'    => 'Verifier <MY-ADDRESS>',
'to'      => '<?php print_r(GET_$[email]) ?>, [email protected]',
'subject' => 'Verifcation & Instructions',
'text'    => 'Dear print_r(GET_$[username]),

Thank you for requesting a service for print_r(GET_$[url]).

To make sure this was you, please <a href="link">click here</a> and verify ...'
));
?>

I know the send is working because of the second address I have set up.

Thanks for any help!


Solution

  • Here is a possible solution as given to me by Mailgun Support: http://blog.mailgun.com/double-opt-in-with-php-mailgun/