SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Mail in PHP
BY
SANA MATEEN
Introduction
• This section introduces the relevant configuration directives, describes PHP’s mail() function, and concludes with
several examples highlighting this function’s many usage variations.
• Configuration Directives
• There are five configuration directives pertinent to PHP’s mail() function. Pay close attention to the descriptions
because each is platform-specific.
• SMTP = string
• Scope: PHP_INI_ALL; Default value: localhost
• The SMTP directive sets the Mail Transfer Agent (MTA) for PHP’s Windows platform version of the mail
function. Note that this is only relevant to the Windows platform
• sendmail_from = string
• Scope: PHP_INI_ALL; Default value: NULL
• The sendmail_from directive sets the From field of the message header.
• sendmail_path = string
• Scope: PHP_INI_SYSTEM; Default value: the default sendmail path
• The sendmail_path directive sets the path to the sendmail binary if it’s not in the system path, or if you’d like to
pass additional arguments to the binary. By default, this is set to the following:
• sendmail -t –i
• smtp_port = integer
• Scope: PHP_INI_ALL; Default value: 25
• The smtp_port directive sets the port used to connect to the server specified by the SMTP directive.
• mail.force_extra_parameters = string
• Scope: PHP_INI_SYSTEM; Default value: NULL
• You can use the mail.force_extra_parameters directive to pass additional flags to the sendmail binary. Note that
any parameters passed here will replace those passed in via the mail() function’s addl_params parameter
Sending E-mail Using a PHP Script
• E-mail can be sent through a PHP script in amazingly easy fashion, using the mail() function.
Its prototype follows:
• boolean mail(string to, string subject, string message [, string addl_headers [, string
addl_params]])
• The mail() function can send an e-mail with a subject and a message to one or several
recipients.
• You can tailor many of the e-mail properties using the addl_headers parameter; you can even
modify your SMTP server’s behavior by passing extra flags via the addl_params parameter.
• On the Unix platform, PHP’s mail() function is dependent upon the sendmail MTA. If you’re
using an alternative MTA (e.g., qmail), you need to use that MTA’s sendmail wrappers.
• PHP’s Windows implementation of the function depends upon establishing a socket
connection to an MTA designated by the SMTP configuration directive.
Sending a Plain-Text E-mail
• Sending the simplest of e-mails is trivial using the mail() function, done using just the three
required parameters, in addition to the fourth parameter which allows you to identify a sender.
Here’s an example:
• <?php
• mail("test@example.com", "This is a subject", "This is the mail body",
"From:admin@example.comrn");
• ?>
• Take particular note of how the sender address is set, including the rn (carriage return plus
line feed) characters.
Taking Advantage of PEAR: Mail and
Mail_Mime
• While it’s possible to use the mail() function to perform more complex operations such as sending to multiple
recipients, annoying users with HTML-formatted e-mail, or including attachments, doing so can be a tedious and
error-prone process. However, the Mail (http://pear.php.net/package/Mail) and Mail_Mime
(http://pear.php.net/package/Mail_Mime) PEAR packages make such tasks a breeze.
• These packages work in conjunction with one another: Mail_Mime creates the message, and Mail sends it. This
• section introduces both packages.
• Installing Mail and Mail_Mime
• To take advantage of Mail and Mail_Mime, you’ll first need to install both packages. To do so, invoke PEAR and
pass along the following arguments:
• %>pear install Mail Mail_Mime
• Execute this command and you’ll see output similar to the following:
• Starting to download Mail-1.2.0.tgz (23,214 bytes)
• ......done: 23,214 bytes
• downloading Mail_Mime-1.7.0.tgz ...
• Starting to download Mail_Mime-1.7.0.tgz (31,175 bytes)
• ...done: 31,175 bytes
• install ok: channel://pear.php.net/Mail_Mime-1.7.0
• install ok: channel://pear.php.net/Mail-1.2.0
• Sending an E-mail with Multiple Recipients
• Using Mime and Mime_Mail to send an e-mail to multiple recipients requires that you identify the appropriate
headers in an array. After instantiating the Mail_Mime class, you call the headers() method and pass in this array,
as demonstrated in this example:
TASK
• Create a html email form with fields just like
you find in compose feature of gmail.
• Write php code to acquire values from the
form and send an email

Weitere ähnliche Inhalte

Was ist angesagt?

Http request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.NHttp request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.N
Navaneethan Naveen
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming Clients
Adil Jafri
 

Was ist angesagt? (17)

Fpt connector
Fpt connectorFpt connector
Fpt connector
 
Mule MongoDB connector
Mule MongoDB connectorMule MongoDB connector
Mule MongoDB connector
 
Http request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.NHttp request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.N
 
Php1
Php1Php1
Php1
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming Clients
 
Bindings of components in mule
Bindings of components in muleBindings of components in mule
Bindings of components in mule
 
SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3
 
PHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for phpPHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for php
 
Testing mule
Testing   muleTesting   mule
Testing mule
 
Installing and configuring apache
Installing and configuring apacheInstalling and configuring apache
Installing and configuring apache
 
Oracle Forms : Transnational Triggers
Oracle Forms : Transnational TriggersOracle Forms : Transnational Triggers
Oracle Forms : Transnational Triggers
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
mush With Xampp
mush With Xamppmush With Xampp
mush With Xampp
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Hypertext Transfer Protocol
Hypertext Transfer ProtocolHypertext Transfer Protocol
Hypertext Transfer Protocol
 
Mule esb usecase
Mule esb usecaseMule esb usecase
Mule esb usecase
 

Ähnlich wie Mail

10135 a 05
10135 a 0510135 a 05
10135 a 05
Bố Su
 

Ähnlich wie Mail (20)

Lecture19
Lecture19Lecture19
Lecture19
 
Motivations and Considerations for Migrating from SMTPD/Sendmail to CSSMTP
Motivations and Considerations for Migrating from SMTPD/Sendmail to CSSMTPMotivations and Considerations for Migrating from SMTPD/Sendmail to CSSMTP
Motivations and Considerations for Migrating from SMTPD/Sendmail to CSSMTP
 
vishal_sharma: python email sending software
vishal_sharma: python email sending software  vishal_sharma: python email sending software
vishal_sharma: python email sending software
 
Lecture19
Lecture19Lecture19
Lecture19
 
i &lt;3 email
i &lt;3 emaili &lt;3 email
i &lt;3 email
 
Ruby
RubyRuby
Ruby
 
window server 2008 mail configuration
window server 2008 mail configurationwindow server 2008 mail configuration
window server 2008 mail configuration
 
Internet mail server
Internet mail server Internet mail server
Internet mail server
 
10135 a 05
10135 a 0510135 a 05
10135 a 05
 
Simple mail transfer protocol
Simple mail transfer protocolSimple mail transfer protocol
Simple mail transfer protocol
 
retrieving the mail
retrieving the mailretrieving the mail
retrieving the mail
 
Email ftp
Email ftpEmail ftp
Email ftp
 
Email ftp
Email ftpEmail ftp
Email ftp
 
Smtp
SmtpSmtp
Smtp
 
Ch22 system administration
Ch22 system administration Ch22 system administration
Ch22 system administration
 
SMTP(true)
SMTP(true)SMTP(true)
SMTP(true)
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer Protocol
 
Mail server
Mail serverMail server
Mail server
 
Mail server
Mail serverMail server
Mail server
 
Unit 3 - Protocols and Client-Server Applications - IT
Unit 3 - Protocols and Client-Server Applications - ITUnit 3 - Protocols and Client-Server Applications - IT
Unit 3 - Protocols and Client-Server Applications - IT
 

Mehr von sana mateen

Mehr von sana mateen (20)

Files
FilesFiles
Files
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Php intro
Php introPhp intro
Php intro
 
Files in php
Files in phpFiles in php
Files in php
 
File upload php
File upload phpFile upload php
File upload php
 
Regex posix
Regex posixRegex posix
Regex posix
 
Encryption in php
Encryption in phpEncryption in php
Encryption in php
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methods
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Xml dom
Xml domXml dom
Xml dom
 
Xhtml
XhtmlXhtml
Xhtml
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Dom parser
Dom parserDom parser
Dom parser
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scripting
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
Unit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structuresUnit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structures
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variables
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scripts
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

Mail

  • 2. Introduction • This section introduces the relevant configuration directives, describes PHP’s mail() function, and concludes with several examples highlighting this function’s many usage variations. • Configuration Directives • There are five configuration directives pertinent to PHP’s mail() function. Pay close attention to the descriptions because each is platform-specific. • SMTP = string • Scope: PHP_INI_ALL; Default value: localhost • The SMTP directive sets the Mail Transfer Agent (MTA) for PHP’s Windows platform version of the mail function. Note that this is only relevant to the Windows platform • sendmail_from = string • Scope: PHP_INI_ALL; Default value: NULL • The sendmail_from directive sets the From field of the message header. • sendmail_path = string • Scope: PHP_INI_SYSTEM; Default value: the default sendmail path • The sendmail_path directive sets the path to the sendmail binary if it’s not in the system path, or if you’d like to pass additional arguments to the binary. By default, this is set to the following: • sendmail -t –i • smtp_port = integer • Scope: PHP_INI_ALL; Default value: 25 • The smtp_port directive sets the port used to connect to the server specified by the SMTP directive. • mail.force_extra_parameters = string • Scope: PHP_INI_SYSTEM; Default value: NULL • You can use the mail.force_extra_parameters directive to pass additional flags to the sendmail binary. Note that any parameters passed here will replace those passed in via the mail() function’s addl_params parameter
  • 3. Sending E-mail Using a PHP Script • E-mail can be sent through a PHP script in amazingly easy fashion, using the mail() function. Its prototype follows: • boolean mail(string to, string subject, string message [, string addl_headers [, string addl_params]]) • The mail() function can send an e-mail with a subject and a message to one or several recipients. • You can tailor many of the e-mail properties using the addl_headers parameter; you can even modify your SMTP server’s behavior by passing extra flags via the addl_params parameter. • On the Unix platform, PHP’s mail() function is dependent upon the sendmail MTA. If you’re using an alternative MTA (e.g., qmail), you need to use that MTA’s sendmail wrappers. • PHP’s Windows implementation of the function depends upon establishing a socket connection to an MTA designated by the SMTP configuration directive.
  • 4. Sending a Plain-Text E-mail • Sending the simplest of e-mails is trivial using the mail() function, done using just the three required parameters, in addition to the fourth parameter which allows you to identify a sender. Here’s an example: • <?php • mail("test@example.com", "This is a subject", "This is the mail body", "From:admin@example.comrn"); • ?> • Take particular note of how the sender address is set, including the rn (carriage return plus line feed) characters.
  • 5.
  • 6.
  • 7. Taking Advantage of PEAR: Mail and Mail_Mime • While it’s possible to use the mail() function to perform more complex operations such as sending to multiple recipients, annoying users with HTML-formatted e-mail, or including attachments, doing so can be a tedious and error-prone process. However, the Mail (http://pear.php.net/package/Mail) and Mail_Mime (http://pear.php.net/package/Mail_Mime) PEAR packages make such tasks a breeze. • These packages work in conjunction with one another: Mail_Mime creates the message, and Mail sends it. This • section introduces both packages. • Installing Mail and Mail_Mime • To take advantage of Mail and Mail_Mime, you’ll first need to install both packages. To do so, invoke PEAR and pass along the following arguments: • %>pear install Mail Mail_Mime • Execute this command and you’ll see output similar to the following: • Starting to download Mail-1.2.0.tgz (23,214 bytes) • ......done: 23,214 bytes • downloading Mail_Mime-1.7.0.tgz ... • Starting to download Mail_Mime-1.7.0.tgz (31,175 bytes) • ...done: 31,175 bytes • install ok: channel://pear.php.net/Mail_Mime-1.7.0 • install ok: channel://pear.php.net/Mail-1.2.0 • Sending an E-mail with Multiple Recipients • Using Mime and Mime_Mail to send an e-mail to multiple recipients requires that you identify the appropriate headers in an array. After instantiating the Mail_Mime class, you call the headers() method and pass in this array, as demonstrated in this example:
  • 8.
  • 9. TASK • Create a html email form with fields just like you find in compose feature of gmail. • Write php code to acquire values from the form and send an email