WP:发送电子邮件后的标题警告

时间:2016-05-27 14:13:26

标签: php wordpress

发送联系表单后,我收到以下错误:

Warning: Cannot modify header information - headers already sent by (output started at /home/clientsc/public_html/mypage/wp-includes/general-template.php:2680) in /home/client/public_html/mypage/wp-includes/pluggable.php on line 1171

当我将下面的函数放在名为functions.php

的文件中时出现此错误
function send_my_awesome_form(){

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

    // get the info from the from the form
    $form = array();
    $form['fullname'] = $_POST['fullname'];
    $form['company'] = $_POST['company'];
    $form['email'] = $_POST['email'];
}

// Build the message
$message  = "Name :" . $form['fullname'] ."\n";
$message .= "Company :" . $form['company']  ."\n";
$message .= "Email :" . $form['email']     ."\n";

//set the form headers
$headers = 'From: Contact form <your@contactform.com>';

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

// Who are we going to send this form too
$send_to = 'myemail@gmail.com';

if (wp_mail( $send_to, $subject, $message, $headers ) ) {
    wp_redirect(home_url( )); exit;
}

 }

 add_action('wp_head', 'send_my_awesome_form');

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您的主题标题中使用了

int counterInt; // as a global variable counterInt = Integer.parseInt(editTextNOI.getText().toString()); // in onCreate() public void poslijeDelaya(final int count) { if (counterInt > 0) { String tekstTrci = editTextHIIVrijeme.getText().toString(); long longTrci = Long.parseLong(tekstTrci); textViewRundiPreostalo.setText(Integer.toString(counterInt)); CountDownTimer timerTrci = new CountDownTimer(longTrci * 1000 + 100, 1000) { @Override public void onTick(long millisUntilFinished) { updateTimer((int) millisUntilFinished / 1000); } @Override public void onFinish() { textViewGlavniTimer.setText("00:00"); imageViewSlikaZaOpisAktivnosti.setImageResource(R.drawable.timer_niski_intenzitet); textViewNatpisZaOpisAktivnosti.setText(getResources().getString(R.string.liiState)); String tekstHodaj = editTextLIIVrijeme.getText().toString(); long longHodaj = Long.parseLong(tekstHodaj); CountDownTimer timerHodaj = new CountDownTimer(longHodaj * 1000 + 100, 1000) { @Override public void onTick(long millisUntilFinished) { updateTimer((int) millisUntilFinished / 1000); } @Override public void onFinish() { textViewGlavniTimer.setText("00:00"); textViewNatpisZaOpisAktivnosti.setText(getResources().getString(R.string.hiiState)); counterInt--; poslijeDelaya(counterInt); } }.start(); } }.start(); } else { textViewNatpisZaOpisAktivnosti.setText("Done"); } } }); 个钩子,所以它太晚了,HTML已经部分显示了。

您必须使用wp_head挂钩:

init

编辑:

add_action('init', 'send_my_awesome_form');