PHP Web Email
|
Sending eMail From PHP
Sending email from a Web site using PHP can be accomplished using the built-in mail() function. This function will in turn use either the computer's mail server or, on Windows, a specified SMTP server. Properly configuring the Web server to send email is a common problem, but once established, it's then only a matter of properly invoking the mail() function to send email using PHP. This tutorial covers how to create and configure a custom PHP mailer application.
PHP Mail Server Configuration
A common misconception is that PHP sends an email. This is not the case. Instead, PHP taps into the computer's established mail server, like sendmail (the default program), postfix, or qmail. These are all normally installed on Linux servers. PHP's configuration file (see the image) points to the external mail application.
PHP on Windows can be configured to use an SMTP server. This can either be an application running on the computer or a network-based SMTP server. However, if the SMTP server requires authentication (a username and password combination), as it does on many networks, third-party PHP code will be required (available by searching online).
The PHP mail() Function
The syntax of the mail() function is (also see the image):
bool mail ( string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] )
The TO address can be in the format of user@example.com or User . Multiple recipients can be separated by commas.
The SUBJECT is the email's subject, and must not contain any newline characters (\n or \r).
The MESSAGE is the body of the email. This can be in plain-text or HTML format (see below).
The fourth argument, ADDITIONAL HEADERS is optional. This argument is normally used to identify the email's From and Reply-To addresses, or to add carbon copy (Cc) and blind carbon copy (Bcc) recipients. Multiple extra headers should be separated with a carriage return-linefeed combination (\r\n), placed within double quotation marks:
mail('me@example.com', 'Subject', 'Message', "From:you@example.com\r\nCc:her@example.com");
You should always specify a FROM address, either when using the mail() function or in PHP's configuration file.
The fifth argument, ADDITIONAL PARAMETERS, can be used to send arguments to the mail program.
|
Article continues:
next page>>
|
|
Download NuSphere PHP IDE
Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.
|
Buy NuSphere PhpED® now
|
Special Team4 Offer
Get 4 copies of PhpED for the price of 3!
Optimum solution for development teams.
|
|
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
|
|
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward, Director of Technology caboodal.com
|
|