PHP使用return语句返回额外的空格?

时间:2017-06-16 10:03:59

标签: php whitespace

我的代码有效,但由于某些奇怪的原因,当我返回一个字符串时,它会增加额外的空间,我认为也是一个新行。 下面的代码工作正常。但是,使用Ajax获取的长度为11时,字符串成功的长度为7,因此这不正确,并且在比较时也不等于“成功”。 我已经查看了其他一些问题,但他们提供的所有解决方案似乎都不适合我。据我所知,在任何地方都没有尾随空格。而且它也不是来自我要求的任何文件。

<?php
/*
Plugin Name: Quotation Rest API
Plugin URI:  
Description: A rest API for sending quotation request through to email using Sendgrid. 
Version: 1.0
Author: Niels  
Author URI:  
*/
add_action( 'rest_api_init',  function () {
  register_rest_route( 'offerte', '/send',array(
    'methods' => 'POST',
    'callback' => 'send_mail',
  ) );
} );
include('MailChimp.php');
use \DrewM\MailChimp\MailChimp;
function send_mail( WP_REST_Request $request) {
    $data = $request['data'];
    $name = htmlspecialchars($request['name']);
    $email = htmlspecialchars($request['email']);
  $comment = htmlspecialchars($request['comment']);
  $website = htmlspecialchars($request['url']);
    $company = htmlspecialchars($request['company']);
    $tel =  htmlspecialchars($request['tel']);
    $mailchimp = htmlspecialchars($request['mailchimp']);
    $dataArray = json_decode($data, true);
  ob_start();
  include('mail.php');
  $mailHTML = ob_get_clean();
  $success = 'success'; 
  if (!empty($mailchimp)) {
// add email to mailchimp list 
    $client = new MailChimp('-us14');// get from setttings
    $list_id = ' ';// get from setttings 
    $result = $client->post("lists/$list_id/members", [
            'email_address' => $email,
            'status' => 'subscribed',
          ]);
  }
    $to = " @icloud.com";// get from setttings 
    $subject = "Offerte van " . $name;// // get from setttings  (maybe...)
    $message = $mailHTML; 
    if(wp_mail( $to, $subject, $message)){
    return $success;
  } else {
    // return 'error'; 
  }
}
?>

0 个答案:

没有答案