Skip to content

Instantly share code, notes, and snippets.

@richartkeil
Last active August 29, 2015 14:12
Show Gist options
  • Save richartkeil/2bf82215d2ca2d0da938 to your computer and use it in GitHub Desktop.
Save richartkeil/2bf82215d2ca2d0da938 to your computer and use it in GitHub Desktop.
<?php
function sendMail($mail_to, $text = null, $title = null, $mail_from = null) {
if(empty($title)) {
$title = "";
}
if(empty($text)) {
$text = "";
}
//validate addresses
if(empty($mail_from)) {
if(validateMail($mail_to)) {
//send mail with from-address
$success = mail((string)$mail_to, (string)$title, (string)$text);
} else {
$success = 0;
}
} else {
if(validateMail($mail_to) && validateMail($mail_from)) {
//send mail without from-address
$success = mail((string)$mail_to, (string)$title, (string)$text, "From: ".(string)$mail_from);
} else {
$success = 0;
}
}
return $success;
}
function validateMail($mail) {
if(filter_var($mail, FILTER_VALIDATE_EMAIL) === false) {
return 0;
} else {
return 1;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>EasyMail - Testumgebung</title>
<?php include("easymail.php"); ?>
</head>
<body>
<?php sendMail("richartkeil@gmail.com", "Test", "This is a test-message!", "horst123@quark.net"); ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment