PHPMailer邮件输入字段隐藏


PHPMailer email input field hidden

谁能告诉我为什么在邮件从gmail到达我的电子邮件habitodigital@hotmail.com后,我没有收到表单输入的$email字段?

一切正常,但我看不到电子邮件地址,无法回复客户。

<?php
$name = trim($_POST['name']);
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$site_owners_email = 'habitodigital@hotmail.com'; // Replace this with your own email address
$site_owners_name = 'Hábito Digital'; // replace with your name
$error = "";
if (strlen($name) < 2) {
    $error['name'] = "Please enter your name";  
}
if (!preg_match('/^[a-z0-9&'''.'-_'+]+@[a-z0-9'-]+'.([a-z0-9'-]+'.)*+[a-z]{2}/is', $email)) {
    $error['email'] = "Please enter a valid email address"; 
}
if (strlen($comments) < 3) {
    $error['comments'] = "Please leave a comment.";
}
if (!$error) {
    require_once('PHPMailer-master/class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->isSMTP();
    $mail->From = $email;
    $mail->FromName = $name;
    $mail->Subject = $subject;
    $mail->AddAddress($site_owners_email, $site_owners_name);
    $mail->Body = $comments;
    // GMAIL STUFF
    $mail->Mailer = "smtp";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 587;
    $mail->SMTPSecure = "tls"; 

    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "ramone@gmail.com"; // SMTP username
    $mail->Password = "***"; // SMTP password
    $mail->Send();
    echo "<div class='alert alert-success'><i class='icon-flag'></i> Congratulations, " . $name . ". We've received your email. We'll be in touch as soon as we possibly can! </div>";
} # end if no error
else {
    $response = (isset($error['name'])) ? "<div class='alert alert-error'><i class='icon-warning-sign'></i>  " . $error['name'] . "</div> 'n" : null;
    $response .= (isset($error['email'])) ? "<div class='alert alert-error'><i class='icon-warning-sign'></i> " . $error['email'] . "</div> 'n" : null;
    $response .= (isset($error['comments'])) ? "<div class='alert alert-error'><i class='icon-warning-sign'></i> " . $error['comments'] . "</div>" : null;
    echo $response;
} # end if there was an error sending
?>

我有这个js文件来处理表单发送消息:

jQuery(function($) {
// These first three lines of code compensate for Javascript being turned on and off. 
// It simply changes the submit input field from a type of "submit" to a type of "button".
var paraTag = $('input#submit').parent('div');
$(paraTag).children('input').remove();
$(paraTag).append('<input type="button" name="submit" id="submit" value="Enviar">');
$('#contact-form input#submit').click(function() {
    $('#contact-form').append('<img src="images/loader.gif" class="loaderIcon" alt="Loading..." />');
    var name = $('input#name').val();
    var email = $('input#email').val();
    var subject = $('input#subject').val();
    var comments = $('textarea#comments').val();
    $.ajax({
        type: 'post',
        url: 'sendEmail.php',
        data: 'name=' + name + '&email=' + email + '&subject=' + subject + '&comments=' + comments,
        success: function(results) {
            $('#contact-form img.loaderIcon').fadeOut(1000);
            $('#response').html(results);
        }
    }); // end ajax
   });
});

我不认为你可以改变你的from地址,当你使用gmail发送消息;Gmail只允许你使用自己的地址,如果你使用其他地址,他们会将其替换为你的地址。

你可以试着添加一个回复地址:

 $mail->AddReplyTo($email, $name);

,但如果这也不起作用,你必须在消息体中发送地址。

作为一个旁注,你应该编码你的值,当你把它们发送到服务器,以确保&, =等字符不会破坏你的查询字符串。您可以使用encodeURIComponent(),或者更简单,使用以下命令:

data: $('form').serialize(),