Recently, while working on the temporary site for Moonfar, I wanted to send the user an email as confirmation that they had signed up for email notifications. Essentially, you define the recipient, the subject line, the body, a few headers, and then call the
mail() function while passing those parameters to it. PHP's
mail() function does the rest, provided that your host has PHP configured properly.
Let me preface this by saying that I've only tested this on GoDaddy's Linux Deluxe Hosting plan. If you are trying to do this with another web host, you need to make sure that the install of PHP you are using supports the
<?php $to = 'email@example.com'; $subject = 'Your subject line'; // the message here is HTML, but you could // use plain text in the same manner // this could also be pulled from a template file $message = ' <html> <head> <title>Your Title Here</title> </head> <body> <p>Your content here...</p> </body> </html>'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers // I'm not sure how the To: field in the header functions since it's part // of the function call, so I've commented it out here //$headers .= 'To: ' . $emailAddr . "\r\n"; $headers .= 'From: YourName <firstname.lastname@example.org>' . "\r\n"; $headers .= 'Cc: ' . "\r\n"; // if you want to receive a copy $headers .= 'Bcc: email@example.com' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?>
It's as easy as that. That said, I read somewhere that there is a 1000 emails per day limit using this method on GoDaddy without paying for outbound emailing services, but I could be mistaken.