SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Fpt connector
Fpt connectorFpt connector
Fpt connectorThang Loi
 
Mule MongoDB connector
Mule MongoDB connectorMule MongoDB connector
Mule MongoDB connectorAnkush Sharma
 
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.NNavaneethan Naveen
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming ClientsAdil Jafri
 
Bindings of components in mule
Bindings of components in muleBindings of components in mule
Bindings of components in mulesathishmca143
 
SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3Ben Abdallah Helmi
 
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 phpaimaq9a
 
Testing mule
Testing   muleTesting   mule
Testing muleSindhu VL
 
Oracle Forms : Transnational Triggers
Oracle Forms : Transnational TriggersOracle Forms : Transnational Triggers
Oracle Forms : Transnational TriggersSekhar Byna
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3Ben Abdallah Helmi
 
Hypertext Transfer Protocol
Hypertext Transfer ProtocolHypertext Transfer Protocol
Hypertext Transfer Protocolselvakumar_b1985
 

What's hot (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
 

Similar to Mail

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 CSSMTPzOSCommserver
 
vishal_sharma: python email sending software
vishal_sharma: python email sending software  vishal_sharma: python email sending software
vishal_sharma: python email sending software vishal sharma
 
window server 2008 mail configuration
window server 2008 mail configurationwindow server 2008 mail configuration
window server 2008 mail configurationanwarkade1
 
10135 a 05
10135 a 0510135 a 05
10135 a 05Bố Su
 
Simple mail transfer protocol
Simple mail transfer protocolSimple mail transfer protocol
Simple mail transfer protocolAnagha Ghotkar
 
retrieving the mail
retrieving the mailretrieving the mail
retrieving the mailtumetr1
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer ProtocolMaitree Patel
 
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 - ITDeepraj Bhujel
 

Similar to 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
 

More from sana mateen

PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopessana mateen
 
Encryption in php
Encryption in phpEncryption in php
Encryption in phpsana mateen
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methodssana mateen
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perlsana mateen
 
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 scriptingsana mateen
 
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 expressionssana mateen
 
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 structuressana mateen
 
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 variablessana mateen
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scriptssana mateen
 

More from 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
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 

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