PHP Mailing List: Setting Up (4/6)

PHP Mailing List: Setting Up (4/6)


Installing and using the Mailgun API so we can easily subscribe users and send out email.

Watch the full series at https://www.youtube.com/playlist?list=PLfdtiltiRHWFxboMVRMelHYreAJO73DPe

Subscribe to phpacademy and enjoy more free web development tutorials!

Our channel
http://youtube.com/phpacademy

Official website
http://phpacademy.org

Support Forum
http://phpacademy.org/forum

Follow us on Twitter!
http://twitter.com/phpacademy
Closed Caption:


We are now going to install
Mailgun's official software
development kit for PHP.
And this basically acts
as a really easy way
to add uses to lists, which
we just create a moment ago,
and do things like send out
email, et cetera, et cetera.
There's lots we can do here.
So, we're going to need to
install this with Composer.
I mean, we don't have to,
but the best way, probably,
to do this, is with Composer.
So if you head
over to Packagist,
and have a search for
mailgun,/mailgunphp,
or probably just mailgunphp.
Now if you don't
have Composer, you're
going to need to
head over to get
to composer.org, and
install the Composer.
Basically Composer is just a
dependency manager for PHP.
And, of course, if we're
building an application that
sends email with mailgun,
then the mailgun PHP SDK
is a dependency.
So, if we basically head
over to a terminal--
this works on Windows as
well-- and run Composer,
that just confirms that
Composer is installed.
So as long as you're within
the mailing list directory,
or wherever you're storing
this, we're good to go.
Now inside of
Sublime, you can see
that I've got a root directory
here, called Mailing List.
I've got subdirectories,
like CSS.
And this is the
markup for the forms
that we'll be looking at later.
Inside of the root
directory though,
if we create a new
file, we're going
to save this as composer.json.
Now what this does
is, it allows us
to specify all of
the dependencies
that we require for our project.
Now, on the Packagist,
you can see here, this
is the dev master, basically
instance of the mailgun@SDK.
So, what we're going to do here
is, once you've created this,
we can then run
Composer Install.
What that'll do, is that
will install the dependency,
and any dependencies that
the mailgun SDK has as well--
you can see that it
has a couple here.
And then that then installed
inside of this vendor folder.
Now, inside of
the vendor folder,
we also have this
autoload.php file,
which we can include
to allow us to access
the functionality
within this mailgun SDK.
So, what we're going to do
is, inside of Mailing List,
we're going to
create a new file.
And I'm going to
call this init.php.
Now inside of here, we're
going to creative everything
that we may need between
confirm.php, send.php,
and subscribe.php.
So this just gives
us the ability
to specify everything
here, so we
don't have to repeat ourself.
Now this can be-- depending
on your application, included
anywhere-- there may be
different ways to do this.
But let's basically create a new
Mailgun instance, a new Mailgun
public instance, and let's
also create an opt-in handler.
We'll look at sort of what
we do with these later.
But the first thing
we need to do,
is actually allow us to take
the Mailgun API, and use it.
So, we include autoload.php
from the vendor folder,
which was installed
with Composer.
Now I'm going to define
here a couple of constants,
and the first one
is Mailgun Key.
Now the Mailgun key is what you
have on your dashboard, over
here.
So we can just copy,
and paste this value,
and we can paste it into there.
And we want to define the
Mailgun public key as well.
Which we also have out
on our dashboard here, so
I can just copy that, and
paste that into there.
So we've defined
them, now there's
a couple of other things that
we need to define as well.
The first one is the domain
that we're working with.
And remember we're working
without test sandbox domain.
So let's say Mailgun
Domain, and all
we need to do here, is
copy and paste this value,
and place that in there.
Now we will also need to go
ahead and define the list
that we're adding users to.
Remember, we've
already created this,
so let's grab the domain
for this-- or the address
for this, rather.
So if we head over
to the mailing lists
tab-- this is the
address for here,
it's basically whatever you
called it at your sandbox
domain, or your domain
if you have one added.
Remember, we can't use
this sandbox in production.
So, we're also going to
define a secret phrase,
or pass phrase if
you like, that allows
us to pass this in when we're
generating things like hashes.
This just ensures that no
one else knows this value,
and they can't generate
hashes on your behalf.
And I'm just going to
write anything in here,
but you can just write a
load of rubbish in here.
It really doesn't matter,
as long as it stays secret.
So now, what we want
to do, now that we've
defined all of
this information--
we're going to be using
this in all of these files,
so it's useful to have
constants like this--
we're going to instantiate
two Mailgun instances,
one providing in our
public key, and one
providing in our private key.
So the first one, we're
just going to call Mailgun.
So Mailgun is actually
name spaced under Mailgun,
so we need to do
this-- Mailgun/mailgun,
and then we provide
in our Mailgun key.
It's as easy as that,
and that gives us
all of the functionality we need
to add users, send email, et
cetera, et cetera.
Now, I'm also going to
create a variable called
Mailgun Validate.
And we use this later on to
validate email addresses.
And what this does is,
when a user's subscribing
to your list, it
validates that this
isn't an email address that's
been marked as a spam email
address, or it doesn't exist, or
if it's just not a valid email
address at all.
So it's not just looking at the
validity of the actual string
you're passing, it looks at the
genuineness of email as well.
So this, instead of
passing in our private key,
we just pass in our public key.
So in this case
it's just PUBKEY.
That's it.
So, we also have
an opt-in handler
that we need to grab from our
Mailgun instance, which is this
here.
So let's create a
Mailgun opt-in variable,
and we will take
this from Mailgun,
and it's an opt-in handler
method that we need to call.
So this allows us to
do things like actually
add uses to lists,
and stuff like that,
but we'll be looking
at that later.
So, what we need to
make sure that we
do is, within each
file, where we want
to access all of
this functionality,
we want to include it.
So I've already created
all the markup for ours.
For the form, you're likely
going to have your own markup,
with your own styles.
But let's create an opening
and ending PHP tag here.
And let's require in init.php.
And this just let's just check
that everything's working.
We want to do that on the
Send file, the subscribe file,
and the confirm file as well.
And we can get rid of the
ending tag on that file.
So, if we head over to here,
and go and subscribe .php.
This is the styles, I've
created a style sheet in here
which contains all
of these styles.
But you're, like I said, likely
to going to have your own.
So, now that we've included
init.php on this page,
it looks like we're
not seeing any errors.
So I can assume that so we've
successfully instantiated,
and done everything we
need to inside of init.php.
So, good to know.
That was a little
bit of a boast,
and it's a little bit
messy, because we're just
putting it all into one file.
But now that's clear, we
can go on, and actually
start to subscribe uses
to our mailing list.

Video Length: 08:25
Uploaded By: Codecourse
View Count: 4,982

Related Software Products
Mailing List Manager PHP
Mailing List Manager PHP

Published By:
RockMIXFM.com

Description:
A Complete Full Featured Email Solution. Don't Waste Your Hard Earned Profits On Expensive Monthly Fees!P Follow the simple instructions and use Mailing List Manager and I guarantee you will TRIPLE the results of your marketing efforts... No Matter What You Are Selling!P If you are looking for an easy to install and easy to use program to handle all of your mailing requirements then look no further. Mailing List Manager will suit your needs.P Whether you're starting a new online ...


Related Videos
PHP Mailing List: Mailgun Control Panel (3/6)
PHP Mailing List: Mailgun Control Panel (3/6)

Want more? Explore the library at https://www.codecourse.com/lessons Official site https://www.codecourse.com Twitter https://twitter.com/teamcodecourse hr / bClosed Caption:/b OK. So go ahead and sign up for a Mailgun account. And once you've signed in, you'll see a dashboard much like this. Now there's a few things that you need from here, so just to be aware ofbr ...
Video Length: 02:47
Uploaded By: Codecourse
View Count: 5,159

Copyright © 2025, Ivertech. All rights reserved.