$output[] = '';
    $output[] = '-----------------------------';
    $output[] = $from_name . ' is using iBegin Share (http://www.ibegin.com/labs/share/)';
    $output[] = '-----------------------------';
    return implode("\r\n", $output);
}
header("Content-Type: text/plain");
if (empty($_GET['from_name']) || empty($_GET['from_email']) || empty($_GET['to_email']) || empty($_GET['to_name'])) {
    header("HTTP/1.1 400 Bad Request");
    echo 'Please fill in all required fields.';
    exit;
} elseif (!iBeginShare::isValidEmail(trim($_GET['from_email']))) {
    header("HTTP/1.1 400 Bad Request");
    echo 'Your email email is invalid.';
    exit;
} elseif (!iBeginShare::isValidEmail(trim($_GET['to_email']))) {
    header("HTTP/1.1 400 Bad Request");
    echo 'Your friend\'s email is invalid.';
    exit;
} else {
    $subject = generateEmailSubject($_GET['title'], $_GET['link'], $_GET['from_name'], $_GET['from_email'], $_GET['to_name'], $_GET['to_email']);
    $body = generateEmailBody($_GET['title'], $_GET['link'], $_GET['from_name'], $_GET['from_email'], $_GET['to_name'], $_GET['to_email'], $_GET['message']);
    $from = $_GET['from_name'] . '<' . $_GET['from_email'] . '>';
    $to = $_GET['to_name'] . '<' . $_GET['to_email'] . '>';
    $headers = array();
    $headers[] = 'From: ' . $from;
    $headers[] = 'Reply-To: ' . $from;
    $headers[] = 'X-Mailer: iBeginShare (PHP/' . phpversion() . ')';
    $headers = implode("\r\n", $headers);
    if (@mail($to, $subject, $body, $headers)) {
        echo 'Your email was sent successfully.';