Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topics Sending an email Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.

Similar presentations


Presentation on theme: "Topics Sending an email Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies."— Presentation transcript:

1 Topics Sending an email Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies

2 Sending an Email –Configuring PHP for Emailing –The Mail Function –Sending Email with Headers –Sending HTML mail

3 Configuring PHP for Emailing If u r using any *NIX environment- sendmail is automatically installed Any hosting Service – service provider will provide sendmail settings If we are not using sendmail- –We can use existing SMTP service –Install a mailserver such as Mailtraq

4 Parameters to set for configuration Once the mail server is installed we need to modify php.ini There are some important parameters to setup –SMTP: Set this to the ip address or DNS name of your SMTP server. (windows installation only) default value : localhost –smtp_port: Set this to the port PHP uses to connect to the SMTP server (windows installation only) default value 25 –Sendmail_from: The From address used by default by the PHP mail() command –Sendmail_path: the path to the sendmail program(*NIX servers only) most servers usr/sbin/sendmail

5 The Mail Function The mail() is used to Send mail using PHP Synatx bool mail ( string $to, string $subject, string $message, [ string $additional_headers,[ string $additional_parameters ]] )

6 parameters –to Receiver, or receivers of the mail. The formatting of this string must comply –subject Subject of the email to be sent. – message Message to be sent. Each line should be separated with a LF (\n). Lines should not be larger than 70 characters  The remaining two are optional

7 Optional Parameters additional_headers (optional) String to be inserted at the end of the email header. This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a LF (\n). additional_parameters (optional) The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting.

8 Multiple Recipients Sending message to multiple recipients- the addresses must be seperated with comma. Syntax: mail(“first@email.com, second@email.com”,”hi”, “wazzup”)first@email.com, second@email.com

9 Some Examples The wordwrap() function wraps a string into new lines when it reaches a specific length. This function returns the string broken into lines on success, or FALSE on failure. Example #1 Sending mail. Using mail() to send a simple email: <?php // The message $message = "Line 1\nLine 2\nLine 3"; // In case any of our lines are larger than 70 characters // we should use wordwrap() $message = wordwrap($message, 70); // Send mail('caffeinated@example.com', 'My Subject', $message); ?>

10 Sending With Headers Example #2 Sending mail with extra headers. The addition of basic headers, telling the MUA the From and Reply-To addresses:

11 Collecting Data and Sending Mail we are going to create two Web pages, mailform.html and email.php The file mailform.html will collect the data you are going to send. The file email.php will actually send the message, using the data you enter. Save the first page as mailform.html. Note that mailform.html doesn’t actually have any PHP code in it. It simply collects the required data in an HTML form. Save the second page as email.php. This second page will take the values entered into the first page, and send them in an e-mail.

12 Mail Form.html Enter EMAIL DATA enter to address enter ur subject Enter ur Message

13 email.php <?php ini_set("sendmail_from", "pradeep@vit.ac.in"); ini_set("SMTP","mail.vit.ac.in"); echo " Welcome to emailing with PHP "; echo " "; $to= $_REQUEST["to"]; $subject= $_REQUEST["subject"]; $message= $_REQUEST["MESSAGE"]; $from = "pradeep@vit.ac.in"; $headers = "From:". $from; $send=mail($to,$subject,$message,$headers); if($send) echo "congrats! The following Mail has been Sent "; echo " To: $to "; echo " From: $from "; echo " Subject: $subject "; echo " Message: "; echo $message; else echo "error in sending mail...."; ?>

14 Running the script Load up the first page, mailform.html, in your browser, and enter some data. Make sure you use valid e-mail addresses so that you can verify their receipt. Click the Send button. A second page appears, similar to the one shown below. Open your e-mail client and check your e- mail

15

16

17

18 How it works Remember that if your email.php page is not in the same folder as mailform.html, you have to provide the correct path: Once the user presses the Send button, email.php is loaded. The first step in your PHP code assigns all the fields from mailform.html to variables. In order to specify from whom the e-mail is coming, use the optional fourth parameter for the mail() function, headers. $headers = “From: “. $from. “\r\n”; The mail() function returns a value of True if it is successful and False if it fails.

19 The mail() function returns a value of True if it is successful and False if it fails. You will use this function to make your application a little more user-friendly: $mailsent = mail($to, $subject, $message, $headers); if ($mailsent) { echo “Congrats! The following message has been sent: ”; echo “ To: $to ”; echo “ From: $from ”; echo “ Subject: $subject ”; echo “ Message: ”; echo $message; } else { echo “There was an error...”; } ?>


Download ppt "Topics Sending an email Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies."

Similar presentations


Ads by Google