Domanda

I am trying to setup a new contact form. I am able to receive the email and the message correctly, but the reply-to is either showing up as (unknown sender) or my username at my nameserver, ex: coggi132@rs14.websitehostserver.net. I've looked at this for 4 hrs now, removing and adding in differnet things I've seen online. It does work if I hardcode an email address into the mail(..."$visitor_email") section. Thanks

Here is the html:

<form id="form" action="../assets/form-to-email.php" method="post">
    <p><label class="required" for="namet">Name</label>(required)<br /><input name="name" id="name" type="text" required/>
<input type="text" style="display:none;" id="zip" name="zip" placeholder="Leave this field blank" autocomplete="off"></p>
    <p><label class="required" for="mailt">E-mail</label>(required)<br /><input name="email" id="email" type="text" required/></p>
    <p><label for="phone">Phone</label><br /><input name="phone" id="phone" type="text" required/></p>
    <p><label class="required" for="message">Message</label>(required)<br /><textarea name="message" id="message" required></textarea></p>
    <p><input class="btn_m" type="submit" name="submit" value="Submit Form" /></p>
</form>

Here's the php

<?php
/*
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}*/
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];

$email_subject = "New Message From NovaWebDev.com Form";
$email_body = "You have received a new message from $name.\n
Phone Number: $phone \n
Here is the message: $message \n".

$to = "info@novawebdev.com";//<== Website's email address
$headers = "From: $visitor_email \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body, $headers);
//done. redirect to success page.
header('Location: /index.php/shared/email_success');


// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
          '(\r+)',
          '(\t+)',
          '(%0A+)',
          '(%0D+)',
          '(%08+)',
          '(%09+)'
          );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}

?> 
È stato utile?

Soluzione 2

I figured this out. My email input was named "mail", while my php was "email". Thanks for the help guys.

Altri suggerimenti

Use this;

$headers = 'From: ' . $visitor_email . "\r\n";
$headers .= 'Reply-To: ' . $visitor_email . "\r\n";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top