This is a function I created to facilitate the sending of PHP emails. Just give it the name and email of who your sending it to, and your name and email. A subject and a message. These options are required. The type, cc and bcc options are optional. By default, the email will be sent as text, so if your sending an HTML email, make sure to set the type to 'html'.
Send Email Function
function send_email($to_name = null, $to_email = null, $from_name = null, $from_email = null, $subject = '', $message = '', $type = 'text', $cc = null, $bcc = null) {
if (!$to_name || !$to_email || !$from_name || !$from_email) return false;
$header = "";
switch($type) {
case 'html':
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
break;
case 'text':
default:
$message = wordwrap($message, 70, "\r\n");
break;
}
$header .= "To: $to_name <$to_email>\r\n";
$header .= "From: $from_name <$from_email>\r\n";
if ($cc) {
$header .= "Cc: $cc\r\n";
}
if ($bcc) {
$header .= "Bcc: $bcc\r\n";
}
$header .= "Date: ".date(r)."\r\n";
$header .= "Reply-To: $from_name <$from_email>\r\n";
$header .= "X-Mailer: PHP/".phpversion();
return @mail($to_name . '<' . $to_email . '>', $subject, $message, $header);
}
broj1
356
Humble servant
Featured Poster
faizan naqvi
0
Newbie Poster
sandimcp
0
Newbie Poster
waheed_z89
0
Newbie Poster
gabrielcastillo
40
Web Developer
coreyavis
13
Dev Poster
gabrielcastillo
40
Web Developer
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
gabrielcastillo
40
Web Developer
coreyavis
13
Dev Poster
carllagerfeld
0
Newbie Poster
coreyavis
13
Dev Poster
Airshow
416
WiFi Lounge Lizard
Team Colleague
coreyavis
13
Dev Poster
Loren_1
0
Newbie Poster
coreyavis
13
Dev Poster
Airshow
416
WiFi Lounge Lizard
Team Colleague
Airshow
416
WiFi Lounge Lizard
Team Colleague
Airshow
416
WiFi Lounge Lizard
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.