Jun 2008
14
11:26am

Sending email using PHP is a pretty straightforward task and this short how to will show you exactly how to do that. The key to sending emails in PHP is the mail() function. Here’s how to to use it:

<?php
// example number 1 - the basic
mail("email@address.com",
 "subject of message",
 "body of message");

// example number 2 - two recipients and specifying email sender
mail("email@address.com,email@address.net",
 "subject of second message",
 "body of message",
 "From: sender@email.com\r\n");

// example number 3 - specifying sender and CC recipient
mail("email@address.com",
 "subject of second message",
 "body of message",
 "From: sender@email.com\r\nCC: email@address.net\r\n");
?>

The mail function accepts at least three parameters namely the recipient, subject and the message. That alone will do most of what you need to do. The power however of the mail() function is in the option fourth parameter which is for adding additional headers. It accepts a string which can contain any valid email header. The second example above shows how to use the fourth header to specify the sender of the email but it can do more than that.

You can specify CC or BCC recipients in it and if you’re up for the challenge, you can use it to add attachments to your email. Yes, I know that’s tough and that really sucks knowing that other scripting languages such as ASP provide a much better and easier way to send emails.

That’s where the PHPMailer Class comes in. It’s a free PHP class that makes sending emails with PHP easier and more powerful. You can download it here and here’s how to use it.

<?php
include("class.phpmailer.php");

// initiate the class
$mail=new PHPMailer();

// let’s use SMTP
$mail->IsSMTP();
$mail->Host="somehost.com";
$mail->Username="smtpusername";
$mail->Password="smtppassword";

// sender
$mail->From="sender@email.com";
$mail->FromName="Billy Joel";

// subject and message
$mail->Subject="email subject";
$mail->Body="email message";

// specify recipients
$mail->AddAddress("email@address.com");
$mail->AddAddress("email@address.net");

// send the email
$mail->Send();
?>

The power of PHPMailer is more than that. Through it you can add attachments to your email, specify an HTML body for your email, etc. Download it and check out the examples they provide.

Happy emailing and please, don’t spam. :)


Share this Post through Social Bookmarking These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb

PHP cURL Cookies Example

Posted by Mike Lopez under PHP cURL
No Comments
May 2008
20
01:01pm

Want to learn how to use PHP cURL with Cookies? Well, it’s pretty simple so let’s go see the code but first let’s make a scenario…

Say we have a page called ‘cookiepage.php’ in a particular website that checks for the cookie set by the homepage and will only return the proper output if the cookie exists. How do you do it? Here’s how…

Read the rest of this entry »

Share this Post through Social Bookmarking These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb
May 2008
20
12:10pm

Do you need to post data to a website using PHP? It’s actually pretty easy to do. Here’s the code.

$urltopost = "http://somewebsite.com/script.php";
$datatopost = array (
"firstname" => "Mike",
"lastname" => "Lopez",
"email" => "my@email.com",
);

Read the rest of this entry »

Share this Post through Social Bookmarking These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb
May 2008
20
12:04pm

Do you want to learn how to use cURL in PHP? Well, if so then this tutorial is for you. But before anything else, what is cURL?

cURL is a command line tool for transferring files with URL syntax. The strong point of cURL is the number of data transfer protocols it supports. It is distributed under the MIT License which makes cURL free software. It supports FTP, FTPS, HTTP, HTTPS, TFTP, SCP, SFTP, Telnet, DICT, FILE and LDAP. - based on Wikipedia’s definition

Read the rest of this entry »

Share this Post through Social Bookmarking These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb
Mar 2008
26
07:34pm

I realized that a lot of people who want to learn PHP are having hard time getting started with it - not because PHP is difficult to use or understand but simply because they don’t know where to start. Because of this, I decided to write this short how-to on getting started with PHP. It covers all the necessary stuff to setup Apache, PHP, and MySQL as well as to install one of my favorite PHP editors.

Read the rest of this entry »

Share this Post through Social Bookmarking These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb
Mar 2008
12
09:10pm

Here’s a nifty little script I use to validate date input with PHP. This function can accept any common date entry and return true if the date is valid or false otherwise.

The Script
<?php

Read the rest of this entry »

Share this Post through Social Bookmarking These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • Technorati
  • YahooMyWeb