0

I've got a problem with this script

<?php
$to      = 'email@gmail.com';
$subject = $_POST['subject'];
$message = $_POST['message'];
$email = $_POST['email'];
$headers = 'From: '. $email . "\r\n" .
    'Reply-To: email2@exaple.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Script sends an email but I can't see Addressee. There is problem with $email variable. If I use <?php echo $email ?> I can see it.

There is a form

<form method="post" action="mail.php">

(...)

 <div class="col-md-4">
            <div class="form-group">
              <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email" required="required">
              <p class="help-block text-danger"></p>
            </div>
          </div>
  • you shouldn't use the mail() function; there are a few good libraries out there to handle this for you: PHPMailer: https://github.com/PHPMailer/PHPMailer SwiftMailer: http://swiftmailer.org/ – Kaylined Feb 08 '17 at 22:44
  • Also your $email var is fine; the problem is probably with your form. – Kaylined Feb 08 '17 at 22:45
  • What is the output of `echo "-".$email."-`? Maybe there's something in there, that shouldn't be in there. Better filter that first (via `$email = filter_var($email, FILTER_VALIDATE_EMAIL)` ). – Jeff Feb 08 '17 at 22:53
  • echo returns me a variable. Why $subject and $message are ok? there are writen in the same way. – Daniel Stanecki Feb 08 '17 at 23:04

0 Answers0