示例#1
0
function send_email($name, $email, $message)
{
    global $m, $to_email, $from_email, $email_subject;
    // If there is an error, the message suggests calling the library. Add your
    // Library's phone number here.
    $library_phone = '(616) 331-3500';
    /*
    	Uncomment the following line if you want to require emails. You should also
    	see the README for information on how to check for emails on the client side
    	with JavaScript.
    */
    //require_field($email, "email address");
    /*
    	Uncomment the following line if you want to require names. You should also
    	see the README for information on how to check for names on the client side
    	with JavaScript.
    */
    //require_field($name, "name");
    // Build the headers
    $headers = "From: " . $from_email . "\r\n";
    $headers .= "Reply-To: " . $from_email . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();
    // Check to make sure there are no really sneaky naught bits in the message
    contains_bad_str($message);
    contains_bad_str($email);
    contains_bad_str($name);
    contains_newlines($email);
    contains_newlines($name);
    // Build the message
    $error_report = $message;
    $error_report .= "\n\n" . 'From: ' . $name;
    $error_report .= "\n" . 'Email: ' . $email;
    // Attempt to send the mail, then set the message variable $m to success or
    // error.
    if ($m == NULL) {
        // There have been no errors, send the email
        if (mail($to_email, $email_subject, $error_report, $headers)) {
            $m = '<div class="lib-success">Thanks for reporting this issue! We&#8217;ll get right on it.</div>';
        } else {
            $m = '<div class="lib-error">Uh-oh. There was a problem sending your report. Maybe try calling the library at ' . $library_phone . '?</div>';
        }
    }
}
if (empty($_POST['email']) or !preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$/', $email)) {
    $email = FALSE;
    $message .= '<br>Please enter a valid email address</br>';
} else {
    $email = $_POST['email'];
}
if (empty($_POST['comments']) or !preg_match('/^11$/', $checksum)) {
    $comments = FALSE;
    $message .= '<br>You did not enter a message or you did not answer the question correctly</br>';
} else {
    $comments = $_POST['comments'];
}
contains_bad_str($email);
contains_bad_str($comments);
contains_newlines($email);
contains_newlines($comments);
if ($comments && $email && $full_name && $checksum) {
    $mail->Subject = "general inquiry";
    $mail->Body .= "Referred from {$previous} \n";
    $mail->Body .= "Name: {$full_name} \n";
    $mail->Body .= "Email Address: {$email}\n";
    $mail->Body .= "Message: {$comments}\n\n\n";
    if (!$mail->Send()) {
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        exit;
    } else {
        $sent = 1;
    }
    echo "<p>If your message requires a response, I will be in touch with you at " . $email . " in due course.</p>";
}