Subscribe

RSS Feed (xml)

PHP-Email: Sending a Simple Email (Part 1)

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:

02  // Setting a timezone, mail() uses this.
03  date_default_timezone_set('America/New_York');
04 
05  // Set email address destination and subject
06  $to = 'example@phpeveryday.com';
07  $subject = 'Test Text Email Only';
08   
09  // Define the headers we want passed. 
10//Note that they are separated by \r\n
11  $headers = "From: me@mysite.com\r\nX-Mailer: Custom PHP Script";
12  
13  // Your message here:
14  $body = "Hi.\n\nHello World!\n\nRegards,\n\nWiwit.";
15   
16  // Finally, send the email
17  mail($to, $subject, $body, $headers);
18  ?>

0 comments:

Related Posts with Thumbnails