Now we know how were going to send the email from the contact farm.
First let's add the P eight p e mail a library to our project.
I've added the cold in a vendor folder as we did in the previous video as this folder is inside the
web root.
Let's also add an H to access file to restrict direct access to files in this folder.
We can copy the one from the includes folder.
Next in the contact page code we can load the p h.
P main classes as we did previously with these lines of code.
Then if the server side validation passes we can use p s p Maila to send the email.
We'll start with the code we wrote in the previous video.
Now we could change the sender address to the address entered into the farm but in reality the email
isn't coming from them it's coming from the account we are using on the s.a. server.
What we can do though is add a reply to address containing the address entered into the farm.
We'll see in a moment how this is used in the email client.
We also want to change the subject.
And the body to the values coming from the farm.
Then if the message is sent successfully we dont want to echo out a message in here.
We want to do it in the astm Owl.
So let's set a variable to true here.
Which will initialize to false at the top.
Then if the message is sent.
Will display a message and otherwise it will show the farm.
Finally if there is an error instead of printing out the error here will add it to the errors array.
Let's give that a try.
If I enter a valid values into the form when I submit it the message is sent.
And in the email client there's the message.
Note that the reply to address has been set to the address I put in the farm so if I click Reply
the reply will be sent to that address.