2015-03-31 45 views
0

我的HTML代码:

<form role="form" method="post" > 
 
    <fieldset> 
 
     <div class="form-group"> 
 
      <input class="form-control" placeholder="Enter Your Email" name="email" type="text" autofocus> 
 
     </div> 
 

 
     <!-- Change this to a button or input when using this as a form --> 
 
     <input type="submit" href="dashboard.php" class="btn btn-lg btn-success btn-block btn-warning" value="Reset" name="sub"> 
 
    </fieldset> 
 
</form>

我的PHP邮件()代码:

$email = $_POST['email']; 
$to = $email; 
$subject = "Password Recovery"; 
$full="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
$reffurl=str_replace("forget_pass_nw_pass.php","",$full); 

$message = "You are receiving this e-mail because you have requested to recover your password."; 

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n"; 

$mail_sent = mail($to,$subject,$message,$headers); 

我试图改变

$ to = $ email

$到= “[email protected]

和它的实际工作。但是当它是$到$电子邮件,没有电子邮件正在发送。

+0

它简单意味着$ _POST [ '电子邮件']要么是空值或此指数不言。你能否显示你的表单代码,因为它不在你提到的代码中。 – 2015-03-31 08:47:28

+0

你是否在你的PHP文件中获得'$ _POST ['email']'的值 – 2015-03-31 08:48:32

+0

我试过echo“$ email”;它实际上会将电子邮件用户类型返回到表单中,而不是空字符串或错误字符串。 – sgchecker 2015-03-31 08:50:06

回答

0
$email=$_POST['email']; 
// Sanitize E-mail Address 
$email =filter_var($email, FILTER_SANITIZE_EMAIL); 
// Validate E-mail Address 
$email= filter_var($email, FILTER_VALIDATE_EMAIL); 
if (!$email){ 
echo "Invalid Sender's Email"; 
} 
else{ 
    $to = $_POST['email']; 
    $to = $email; 
$subject = "Password Recovery"; 
$full="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
$reffurl=str_replace("forget_pass_nw_pass.php","",$full); 

$message = "You are receiving this e-mail because you have requested to recover your password."; 

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n"; 

$mail_sent = mail($to,$subject,$message,$headers); 
+0

@Iftikhar担心的是,它被用来检查电子邮件是否被声明 – Ghostman 2015-03-31 08:52:07

1

看起来像一个额外的间距问题。 变化

$email = $_POST['email']; 

$email = trim($_POST['email']);