PHP: Simple Send Email Function

Here we will give you code snippets or tips related to PHP/MySQL/XHTML/CSS/JavaScript/AJAX development
Forum rules
Be civilized... # Seja civilizado... # Être civilisé...

PHP: Simple Send Email Function

Postby weblivehelp on Mon Jun 02, 2008 9:56 pm

Hi there,

This month we'll provide you with a very simple script to send an HTML Email.

Code: Select all
function sendEmail($name, $email, $to_mail, $subject, $msg) {
   $sending = false;
   $eol = "\n";
   $tosend = array();
   
   if (!empty($name) && !empty($email) && !empty($to_mail) && !empty($subject) && !empty($msg)) {
      $from_name = $name;
      $from_mail = $email;
      $sending = true;
   }
   
   if ($sending) {
         $tosend['email'] = $to_mail;
         $tosend['subject'] = $subject;
         
         $tosend['headers'] = "From: \"".$from_name."\" <".$from_mail.">".$eol;
         $tosend['headers'] .= "Content-type: text/html; charset=iso-8859-1".$eol;
         $tosend['message'] = "
<html>
<head>
<title>".$subject."</title>
</head>
<body>
<br />
".$msg."
<br />
</body>
</html>".$eol.$eol;
      
      if (mail($tosend['email'], $tosend['subject'],  $tosend['message'] , $tosend['headers']))
         return true;
      else
         return false;
   }//-- if ($sending)
   return false;
}

//-- Usage:
$msg = "
   Hey there, please go and visit <a href="http://forum.weblivehelp.net/">http://forum.weblivehelp.net/</a>!! It rocks!!!
";
sendEmail("WebLive Help", "info(at)weblivehelp.net", "someone@somewhere.com", "Hi! Have you seen WebLive Help?? They Rock!! :D", $msg);
//-- Note the (at) has to be a @, we just put (at) due to spam protection

weblivehelp
Site Admin
 
Posts: 9
Joined: Thu May 01, 2008 3:23 pm

Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron