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

时间:2017-02-01 07:36:56

标签: php wordpress phpmailer

以下代码应在表单提交时发送电子邮件:

wp_mail

对应该纠正的内容有何帮助? 我甚至尝试使用以下代码对我的SMTP服务器验证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'; } : 来源(https://gist.github.com/butlerblog/c5c5eae5ace5bdaefb5d

// Delete all files in given directory
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let dataPath = NSURL(fileURLWithPath: path)
if let enumerator = FileManager.default.enumerator(atPath: dataPath.path!) {
    while let fileName = enumerator.nextObject() as? String {
        do {
            try FileManager.default.removeItem(atPath: "\(dataPath)\(fileName)")
        }
        catch let e as NSError {
            print(e)
        }
        catch {
            print("error")
        }
    }
}

1 个答案:

答案 0 :(得分:0)

呃,你实际上并没有告诉它发送!您正在设置一系列设置,而这一切都是如此。您需要致电send()才能实际发送任何内容。添加此项(包括基本错误处理):

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