PHP: Simple Send Email Function
Hi there,
This month we'll provide you with a very simple script to send an HTML Email.
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