由於某種原因名稱,當我收到電子郵件時,電子郵件和消息顯示爲空。PHP mail()函數發送空變量
HTML
<form method="post" action="send.php" class="form-horizontal">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-4">
<input id="name" name="name" type="text" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-4">
<input id="email" name="email" type="email" class="form-control input-md" required="">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="message">Message</label>
<div class="col-md-4">
<textarea class="form-control" id="message" name="message"></textarea>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" name="submit" type="submit" value="Submit" class="btn btn-outline-inverse btn-lg">Submit</button>
</div>
</div>
</fieldset>
</form>
PHP代碼簡單的例子
<?php
$emailto = "[email protected]";
$subject = "Example subject";
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$message = Trim(stripslashes($_POST['message']));
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$body = "<p>You have received a new message:</p>
<p><strong>Ime: </strong> {$name} </p>
<p><strong>Email Address: </strong> {$email} </p>
<p><strong>Poruka: </strong> {$message} </p>";
$success = mail($emailto, $subject, $body, $headers);
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
出於某種原因變量$名稱,$ email和$消息出現空當我收到一封電子郵件從這個聯絡形式/郵件功能。其餘顯示正確。
你檢查了'$ _POST'包含'name'等嗎? –
你重新測試了簡化ied代碼? –
我同意@Jack – joaofgf