dongzhou1865 2017-02-01 07:36
浏览 59

在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';
}
  • 写回答

1条回答 默认 最新

  • dphdh395195 2017-02-01 11:36
    关注

    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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看