Jump to content

Need users email address from the form to be the "reply to" address once i receive

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
hi im sure this question has been asked and answered a few times, however i searched the FAQ's and has no luck finding it. i looked untill page # 8 of the FAQ's.

We need to have the users email address from the form they filled out on our site to be the "reply to" address once i receive the data to my inbox.
we would like to set our auto-responder to automatically send a message to that user and not to the data receiving email

here is the php we need to adjust Please help us learn by showing us the secrete code that makes the magic happen.

Thanking you in advance for your efforts to help us

PHP FORM TO MAIL:
<?php


$subject = 'Request For Golf Brochure - User Contact Info'; 


$emailadd = 'emil@mediababy.net'; 


$url = '/'; 


$req = '1'; 


$text = "Results from form:\n\n"; 

$space = ' ';

$line = '

';

foreach ($_POST as $key => $value)

{

if ($req == '1')

{

if ($value == '')

{echo "$key is empty";die;}

}

$j = strlen($key);

if ($j >= 20)

{echo "Name of form element $key cannot be longer than 20 characters";die;}

$j = 20 - $j;

for ($i = 1; $i <= $j; $i++)

{$space .= ' ';}

$value = str_replace('\n', "$line", $value);

$conc = "{$key}:$space{$value}$line";

$text .= $conc;

$space = ' ';

}

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');


?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>


<head>

<title>FormToEmail.php</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>


<body bgcolor="#ffffff" text="#000000">


<div>

<center>

  <p><b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>

    <br>

    <br>

  Your information was received. Shortly, we will send you an email confirming your request<span style="text-align: center">.</span><br>

  <br>

  <img src="NEB_thankyou.jpg" width="550" height="200"></p>

  <p><input type="button" value="Close Window" onClick="window.close()">

<br>

  </p>

</center>

</div>


</body>

</html>


</body>

</html>

FORM:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Nebraska-ContactForm</title>

<style type="text/css">

#ContactForm p span {

	font-size: 14px;

}

body {

	text-align: justify;

}

</style>

<script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script>

<script src="SpryAssets/SpryValidationRadio.js" type="text/javascript"></script>

<script type="text/javascript">

function MM_validateForm() { //v4.0

  if (document.getElementById){

    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);

      if (val) { nm=val.name; if ((val=val.value)!="") {

        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

        } else if (test!='R') { num = parseFloat(val);

          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

            min=test.substring(8,p); max=test.substring(p+1);

            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

    } if (errors) alert('The following error(s) occurred:\n'+errors);

    document.MM_returnValue = (errors == '');

} }

</script>

<link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css" />

<link href="SpryAssets/SpryValidationRadio.css" rel="stylesheet" type="text/css" />

</head>

<body>

<form id="ContactForm" name="ContactForm" method="post" action="FormToMail.php">

  <p><img src="NEB_pi_03111_580x350edit.jpg" width="580" height="312" alt="" /><br />

    <br />

    Nebraska offers an endless string of outstanding golf opportunities.  The brochure is Nebraska's <br />

    latest tool for planning your next getaway, plus you will receive our monthly e-newsletters. <br />

    <label><script type="text/javascript">

var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1");

var sprycheckbox2 = new Spry.Widget.ValidationCheckbox("sprycheckbox2");

var spryradio1 = new Spry.Widget.ValidationRadio("spryradio1");

</script>      <br style="text-decoration: underline;" />

  Please fill out your contact information and click "Submit"  at the bottom of this page.<br />

      <br />

      First Name<br />

      <input name="firstname" type="text" id="firstname" />

    </label>

    <br />

    <label>Last Name<br />

      <input name="lastname" type="text" id="lastname" />

    </label>

    <br />

    <label>Street Address<br />

      <input name="street address" type="text" id="street address" />

    </label>

  <br />

  <label>City<br />

    <input name="city" type="text" id="city" />

  </label>    

  <br />

  <label for="state">State</label>

  <br />

    <select name="state2" id="state">

      <option>AL</option>

      <option>AK</option>

      <option>AZ</option>

      <option>AR</option>

      <option>CA</option>

      <option>CO</option>

      <option>CT</option>

      <option>DE</option>

      <option>FL</option>

      <option>GA</option>

      <option>HI</option>

      <option>ID</option>

      <option>IL</option>

      <option>IN</option>

      <option>IA</option>

      <option>KS</option>

      <option>KY</option>

      <option>LA</option>

      <option>ME</option>

      <option>MD</option>

      <option>MA</option>

      <option>MI</option>

      <option>MN</option>

      <option>MS</option>

      <option>MO</option>

      <option>MT</option>

      <option>NE</option>

      <option>NV</option>

      <option>NH</option>

      <option>NJ</option>

      <option>NM</option>

      <option>NY</option>

      <option>NC</option>

      <option>ND</option>

      <option>OH</option>

      <option>OK</option>

      <option>OR</option>

      <option>PA</option>

      <option>RI</option>

      <option>SC</option>

      <option>SD</option>

      <option>TN</option>

      <option>TX</option>

      <option>UT</option>

      <option>VT</option>

      <option>VA</option>

      <option>WA</option>

      <option>WV</option>

      <option>WI</option>

      <option>WY</option>

    </select>

    <label>    </label>

    <label><br />

      Zip Code<br />

      <input name="zipcode" type="text" id="zipcode" />

      <br />

    </label>

Email Address<br />

      <input name="emailaddress" type="text" id="emailaddress" />

      <br />

      Please send me your golf brochure via:<br />

  <span id="spryradio2">

      <label>

        <input type="radio" name="Delivery Method" value="USPS" id="RadioGroup1_0" />

        USPS</label>

      <br />

      <label>

        <input type="radio" name="Delivery Method" value="email" id="RadioGroup1_1" />

        email

      </label>

      <br />

    <span class="radioRequiredMsg">Please select type mail delivery.</span></span><br />

<input type="submit" onclick="MM_validateForm('radio','','R','firstname','','R','lastname','','R','street address','','R','city','','R','zipcode','','R','email address','','R');return document.MM_returnValue" value="Submit" />

</form>

<script type="text/javascript">

var spryradio2 = new Spry.Widget.ValidationRadio("spryradio2");

</script>

</body>

</html>



#2
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
Hi there Emil

There is a 4th parameter that can be passed to the PHP function mail().

You need to pass the Reply-To header in with your From one.

$replyto = "test@example.com";

$headers = "From: $emailadd\r\nReply-To: $replyto\r\n"; 

mail($emailadd, $subject, $text, $headers);

You can set the $replyto variable to be the email address from your form, and there you go!

Hope this helps!

#3
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
good morning! thank you for that code.
should i replace the "test@example.com with the my email address or leave it as
test@example.com

#4
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
ok i feel this solution only allows me to predetermin a particular email addres that i can manually put in as the reply to address no? it is now replying to test@example.com
from looking at the code you provided me, i noticed that it is calling the email address from "emailadd" which i am using as the code for my receiving email address where i am receiving the data.

any thoughts? thanks

wwarren said:

Hi there Emil

There is a 4th parameter that can be passed to the PHP function mail().

You need to pass the Reply-To header in with your From one.

$replyto = "test@example.com";

$headers = "From: $emailadd\r\nReply-To: $replyto\r\n"; 

mail($emailadd, $subject, $text, $headers);

You can set the $replyto variable to be the email address from your form, and there you go!

Hope this helps!


#5
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
Obviously yes, you can change the value of $replyto to whatever you want, even $emailadd. You could even just cut out the middle man and do:

$headers = "From: $emailadd\r\nReply-To: $emailadd\r\n"; 

mail($emailadd, $subject, $text, $headers);

But now I have a question for you: Why are you sending an email TO $emailadd and also making it look like it came FROM $emailadd?

#6
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
im not sure that is what i wanted. i need it to look like it came from the user filling out the form.

wwarren said:

But now I have a question for you: Why are you sending an email TO $emailadd and also making it look like it came FROM $emailadd?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users