. Updated Daily. Editions SDA India   SDA Indonesia
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Friday, 9 February 2007

How to Generate and Send Emails in PHP

 

 

The WebCheatSheet.com have published a tutorial to demonstrate how to generate and send e-mails in PHP. The tutorial guides you on the know-how of sending automated messages from PHP applications. It says, this can be in direct response to a user's action, such as signing up for your site, or a recurring event at a set time, such as a monthly newsletter. To understand how to send each variation that may exist on e-mail, the author explains in the following three stages:

Sending a Simple Text Email

It explains that PHP includes the mail()function for sending e-mail, which takes three basic and two optional parameters. These parameters are, in order, the e-mail address in send to, the subject of the e-mail, the message to be sent, additional headers you want to include and finally an additional parameter to the Sendmail program. The mail() function returns True if the message is sent successfully and False otherwise. He gives an example to illustrate the point. The tutorial says that more receivers can be added by either including addresses, comma separated, to the variable, or by adding cc: or bcc: headers. If you don't receive the test mail, it shows that either you have probably installed PHP incorrectly, or may not have permission to send emails, the tutorial informs.

Sending HTML E-mail

The next step, the tutorial delves is to examine how to send HTML e-mail. However, it says that some mail clients cannot understand HTML e-mails. Therefore it is best to send any HTML e-mail using a multipart construction, where one part contains a plain-text version of the e-mail and the other part is HTML. If your customers have HTML e-mail turned off, they will still get a nice e-mail, even if they don't get the entire HTML markup. A code example is used to facilitate better understanding.

Sending E-mail with Attachment

The last variation that the tutorial considers is to send an e-mail with attachments. To send an e-mail with attachment it uses the multipart/mixed MIME type that specifies that mixed types will be included in the email. Moreover, the multipart/alternative MIME type is used to send both plain text and HTML version of the e-mail. The example provided as a part of the tutorial provides you more clarifications.


However to get the entire process working, there are some prerequisites. You need a working e-mail server that you have permission to use. It verifies that for Unix machines, Sendmail is used often; for Windows machines, you must set the SMTP directive in your php.ini file to point to your e-mail server reports the tutorial.

 

Read the Article

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use