Technical & Scientific > Programming

PHP mail through Gmail servers

<< < (2/3) > >>

micah:
I used to use mandrill when it was free for low usage. It was developed by mailchimp but when they started charging for all tiers, they started branding the mailchimp aspect more.  That's when I switched to mailgun which I like much better.

ober:
Thanks guys.  There's a reason I post here before anywhere else.  You guys are awesome.  Fucking StackOverflow assholes just gave me a bunch of grief and basically posted the same example code that I posted as an 'answer'.

I'm going to give Mailgun a shot.  I'll see how that goes.  THANK YOU!

hans:
There's also SendGrid if I remember right. Not sure what they've been up to since the Mandrill deal a few years back. I think they tried to offer something similar but at the time I wasn't as impressed by their API. It may have gotten better by now though.

Also, that's one of the reasons I don't find SO as useful these days. Way to over moderated. I get what they're trying to do but I just don't agree with it. I often find my answers through other means these days. It's hard to actually get anything answered there without it getting flagged as a duplicate, off topic, or whatever.

micah:
If you're interested, here's my code that sends to mailgun

It assumes some existing variables (like $subject and $message) and constants like MAILGUN_API_Key and MAILGUN_Base_URL that I set elsewhere, plus it is set up to accepts attachemets as well but you can leave that out.


--- Code: ---$mail_array = array('from' => 'someone@mysite.com,
'to' => array("to"=> 'someone@somewhere.com',"bcc"=>"someoneelse@somewhere.com"),
                  'subject' => $subject,
                  //'text' => 'plain text message';
                  'html' => '<html>'.$message.'</html>');

if (count($attachments) > 0) {
$i = 1;
foreach ($attachments as $attachment) {
$mail_array['attachment[' . $i . ']'] = curl_file_create($attachment);
$i++;
}
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:'.MAILGUN_API_Key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, rtrim(MAILGUN_Base_URL,"/").'/messages');
curl_setopt($ch, CURLOPT_ENCODING, 'multipart/form-data');
curl_setopt($ch, CURLOPT_POSTFIELDS, $mail_array);
           
$result = json_decode(curl_exec($ch));
curl_close($ch);
--- End code ---

ober:
How long did it take for your DNS/MX records to update?  And thanks for the code.  I'll use that.  I started down the path of the PHP library but my project isn't PSR-7.  :(

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version