Chapter5 Email Handling Notes
Chapter5 Email Handling Notes
2
COMPONENTS OF MAIL SYSTEM
Mail User Agent(MUA):The MUA is the application the originating
sender uses to compose and read email, such as Eudora, Outlook, etc.
POP3
IMAP4
5
1.SMTP
SMTP stands for Simple Mail Transfer Protocol. It
was first proposed in 1982. It is a standard protocol used
for sending e-mail efficiently and reliably over the
internet.
Sender (From:)
This field describes the ‘from’ address of the email. This will specify the sender’s email address.
Usually, it will be the “reply-to” address.
Reply-to
This field describes the email address that will become the recipient of the reply to the particular
email. When you reply, it will go to this email address despite the sender email address.
Recipient (To:)
This is the first/last name of the email recipient as configured by the sender.
Attachments
Some emails could be attached with files such as text, image, audio, video etc. These files are
specified here.
2) Body
The actual content is stored in this part. This will be in the format of text. This field could also
include signatures or text generated automatically by the sender’s email system. 10
2.4 SENDING EMAIL WITH PHP
PHP must be configured correctly in the php.ini file
with the details of how your system sends email.
Open php.ini file available in /etc/ directory and find
the section headed [mail function].
The configuration for windows:
12
PARAMETER DESCRIPTION
character set
15
Email handling with PHP
16
EXAMPLE
EMAIL ID VALIDATION
There are different methods to validate an email
address in PHP.
17
METHOD 1: EMAIL VALIDATION USING
REGULAR EXPRESSION.
18
HTML FORM
<HTML>
<BODY>
</form>
</body>
</html>
20
<?php
// PHP program to validate email
$str=$_POST[‘txtmail’];
//parse unnecessary characters to prevent exploits
$email=htmlspecialchars(stripslashes(strip_tags($str)));
//checks to make sure the email address is in a valid
?>
METHOD 2: EMAIL VALIDATION USING
FILTER_VAR() METHOD.
<?php
$email = “[email protected]";
if (filter_var($email,
FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email address");
}
else {
echo("$email is not a valid email address");
}
22
?>
METHOD 3: EMAIL VALIDATION USING
FILTER_SANITIZE_EMAIL FILTER.
<?php
$email = “[email protected]";
// Remove all illegal characters from email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
24
checkdnsrr() Function
The checkdnsrr() function is an inbuilt function in PHP which is used
to check the DNS records corresponding to the hostname or IP
address. This function can be used to verify whether a domain name
exists or not.
<?php
$domain=“www.gmail.com";
if(checkdnsrr($domain,"MX")) {
26
Email handling with PHP
29
THANK YOU !