-1
出於某種原因,我得到未定義的變量和字符串數組轉換 我不明白,爲什麼無論這些正在發生的事情未定義的變量變量聲明
Notice: Undefined variable: body in C:\Users\New\Desktop\xampp\htdocs\yakov\sendemail.php</b> on line <b>20
Notice: Array to string conversion in C:\Users\New\Desktop\xampp\htdocs\yakov\sendemail.php on line 33
"Array'services.html: ''services.html'\n\n'new york: ''new york'\n\n'new york: ''new york'\n\n'round_trip: ''round_trip'\n\n'2016-09-16: ''2016-09-16'\n\n'2016-09-23: ''2016-09-23'\n\n'nonstop: ''nonstop'\n\n'flexible: ''flexible'\n\n'Business: ''Business'\n\n'1 Adult: ''1 Adult'\n\n'some: ''some'\n\n'one: ''one'\n\n'[email protected]: ''[email protected]'\n\n'new york: ''new york'\n\n'dsfa\n: ''dsfa\n'\n\n'4127117117: ''4127117117'\n\n'me: ''me'\n\n;"
這裏是我的代碼這是導致我試圖玩弄它的問題
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contacting us. We will contact you as early as possible.'
);
//print phpinfo();
error_reporting(-1);
ini_set('display_errors', 'On');
//set_error_handler("var_dump");
$body;
$email;
$subject;
$email_from;
$email_to = '[email protected]';
if (!empty($_REQUEST)) {
$body;
foreach($_REQUEST as $key => $val) {
if (isset($_REQUEST[$key])) {
$body .= "'". $_REQUEST[$key] .": '" . $val . "\n\n";
}
}
$email = isset($_REQUEST['email']) ? trim(stripslashes($_REQUEST['email'])) : "NA";
$subject = isset($_REQUEST['subject']) ? trim(stripslashes($_REQUEST['subject'])) : "NA";
$body .= ";";
$email_from = $email;
//$email_to = '[email protected]';// your email
$body;
}
$success = mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status .$body);
//}
die;
任何其他建議,將不勝感激,因爲我是新來的後端
首先:你正在做的只是$ body;很多。首先將它定義爲一個字符串,不要重新定義它($ body ='';) – user3791775