在WordPress中,wp_mail不会为我的自定义表单发送邮件

Below code should send email on form submission:

function form_submit() {

if (isset($_POST['submit'])) {

    // get the info from the form
    $to = sanitize_email($_POST['email']);

    // The email subject
    $subject = 'you got mail';

    // Build the message
    $message = 'Message from...';

    //set the form headers
    $headers = array('Content-Type: text/html; charset=UTF-8', 'From: Me <onlineform@example.com');

    //send the mail
    $sendmail = wp_mail($to, $subject, $message, $headers);

    return $sendmail;
}
}

Any assistance on what should be corrected? I have even tried authenticating wp_mail with my SMTP server using below code: Source (https://gist.github.com/butlerblog/c5c5eae5ace5bdaefb5d)

add_action('phpmailer_init', 'send_smtp_email');

function send_smtp_email($phpmailer) {

$phpmailer->isSMTP();
$phpmailer->Host = 'example.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = '465';
$phpmailer->Username = 'me@example.com';
$phpmailer->Password = 'password';
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->From = 'me@example.com';
$phpmailer->FromName = 'Me';
}

Uh, you're not actually telling it to send! You're setting a bunch of settings and that's all. You need to call send() in order for it to actually send anything. Add this (includes basic error handling):

if (!$phpmailer->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $phpmailer->ErrorInfo;
}