0% found this document useful (0 votes)
19 views2 pages

Chapter 4 PHP

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Chapter 4 PHP

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 4 PHP

1. List attributes of cookie.

Answer:

Attributes of Cookies are as follows:

• name

• value

• expire

• path

• domain

2. Develop a simple procedure of sending email.

Answer:

Simple Procedure for Sending Email in PHP


1. Configure PHP.ini for SMTP
 Locate the php.ini file in your PHP installation directory. You can use a text editor
to open and edit this file.
 Find the section [mail function].
 By default, the SMTP setting might be commented out with a semicolon (;).
Uncomment this line and set the value to your SMTP server address. For example:
SMTP = smtp.example.com

 The default port for SMTP is 25. You can uncomment the smtp_port line and set it to
25 if it's commented out.
 If your SMTP server requires authentication, you'll need to add the following lines
after the SMTP line:
auth_username = [email protected]
auth_password = your_password

 Save the changes to the php.ini file.


 Restart your web server for the changes to take effect.
2. Sending the Email using PHP mail() function
Here's a basic structure for sending an email using the mail() function in PHP:
PHP
<?php

$to = "[email protected]";
$subject = "Your Email Subject";
$message = "This is the email message body.";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";

if (mail($to, $subject, $message, $headers)) {


echo "Email sent successfully!";
} else {
echo "Error sending email.";
}

?>

Explanation of the code:


 $to: This variable stores the recipient's email address.

 $subject: This variable stores the subject of the email.

 $message: This variable stores the body of the email message.

 $headers: This variable stores the email headers, including the sender's email

address and any CC recipients.


Additional Considerations
 The mail() function might not be reliable on some shared hosting servers. In such
cases, you might need to consider using a third-party email library like PHPMailer.
 This is a very basic example of sending an email. You can customize the headers to
include additional information like Reply-To and BCC.
 For security reasons, it's not recommended to store your email password directly in
the script. Consider using environment variables or a configuration file to store
sensitive information.

You might also like