>> DAVID MALAN: Let's improve upon the website I'm making, via which freshman
can register for intramural sports, by emailing them when they have
registered.
How to do this-- well, here in froshims-3, notice that the only
change I've made now is to update the value of action to register-3.php.
In register-3.php now, notice that I'm first requiring a file called
class.phpmailer.php.
This belongs to a library called PHPMailer that exists somewhere inside
of the computer, and I'm specifying here that PHP should require its use,
just like #include in C requires a header file.
>> Next I check if name is not empty and gender is not empty and dorm is not
empty, then let's proceed to do the following.
First I'm going to even instantiate an object of type PHPMailer.
This is somewhat new syntax, but it's a feature of an object-oriented
programming language, which PHP is.
In particular, this effectively declares a variable of type PHPMailer
and calls ultimately that variable mail.
Let's now use that variable to send an email.
>> Let's first specify by calling a function called isSMTP that I would
indeed like to send this email using the protocol SMTP.
Let's next specify that the host via which I'll send this mail shall be,
for instance here on campus, smtp.fas.harvard.edu.
Let's then set the from address of this email to jharvard@cs50.net.
Let's then add the address of jharvard@cs50.net so that, simply,
this time John Harvard will be emailing himself.
And let's then set the subject of this email to registration.
>> Lastly, let's set the body of this email to be the following string.
This person just registered.
Name--
such and such.
>> Captain--
such and such.
Gender--
such and such.
Dorm--
such and such.
Notice that this string extends onto multiple lines, but I've concatenated
them together using PHP's dot operator so that at end of the day, this is
real just one long string broken here in my text editor onto multiple lines.
>> Now it's time to send the email.
Here I'll call a function called Send, but I'll check whether it's return
value is false.
If so, I'm simply going to die, so to speak, by printing that error.
>> Now notice one other piece of syntax.
Throughout these several lines of code, I've made use
of this arrow operator.
Much like in C, where the arrow operator dereferences a pointer and
leads you to some value, similarly here does this allow you to access a
field inside of an object, in this case an object of type PHPMailer.
Now were I to now visit this page, I'd see the following.
If I now provide David Malan as my name, captain as captain, I'll specify
mail, and I'll live here in Matthews and then click register, I should soon
receive that email.