我的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 mail()代码:
$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: <noreply@caveo.sg>' . "\r\n";
$mail_sent = mail($to,$subject,$message,$headers);
我试过改变
$ to = $ email
到
$ to =“xxx@gmail.com”
它确实有效。但当它是$ to $ email时,没有发送电子邮件。
答案 0 :(得分:1)
看起来像是一个额外的间距问题。 改变
$email = $_POST['email'];
到
$email = trim($_POST['email']);
答案 1 :(得分: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: <noreply@caveo.sg>' . "\r\n";
$mail_sent = mail($to,$subject,$message,$headers);