phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Email: Sending a Simple Email (Part 1)

Tag: email   Category: PHP Basic
post: 18 Nov 2007 read: 2,617


This is a part of tutorial series about sending email in PHP. We know, many different type of email get sent. Email can contains file attachments, inline images, dual format (HTML/text), and so on. We begin with simple email. It use basic function, mail().

To understand how to send a simple email, you can look following code:


  <?php
  // Setting a timezone, mail() uses this.
  date_default_timezone_set('America/New_York');

  // Set email address destination and subject
  $to = 'example@phpeveryday.com';
  $subject = 'Test Text Email Only';
  
  // Define the headers we want passed.  
//Note that they are separated by \r\n
  $headers = "From: me@mysite.com\r\nX-Mailer: Custom PHP Script";
 
  // Your message here:
  $body = "Hi.\n\nHello World!\n\nRegards,\n\nWiwit.";
  
  // Finally, send the email
  mail($to, $subject, $body, $headers);
  ?>


Series this article:
Email: Sending a Simple Email (Part 1)
Email: Sending a Simple HTML Mail (Part 2)
Email: Sending Dual Format (Part 3)
Email: Send Attachement Mail
PHP Email: Using Embedded Images in HTML Email
PHP Email: Sending Mass Email use BCC
PHP Email: Protecting Email Address from Spam Collectors

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting