Page 1 of 1

Newbie: Email form to submitter...

Posted: Thu Mar 19, 2009 12:05 pm
by jfavero
OK, I'm pretty much illiterate when it comes to PHP, just trying to get into it. I hijacked some php code from a website, and forgot to bookmark it. I have the following line

Code: Select all

<?
$subject="from ".$_GET['your_name'];
$headers= "From: ".$_GET['your_email']."\n";
 $headers.='Content-type: text/html; charset=iso-8859-1';
mail("my@email", $subject,  "
 
<html>
<head>
 <title>Thank you for commenting on the EIS</title>
</head>
<body>
 
<br>
  ".$_GET['message']."
</body>
</html>" , $headers);
echo ("Your message was successfully sent!");
?>
<script>
    resizeTo(300, 300)
        //window.close()
</script>
 
I want it to also take a form field we'll call email, grab the email address and mail the completed form to the submitter.

Code: Select all

<input name="email" type="text" class="form_1" id="email" size="30"/>

Re: Newbie: Email form to submitter...

Posted: Fri Mar 20, 2009 3:57 am
by mattpointblank
You just need to make a form using the inputs named as they are in your php (eg 'your_name') and point it at the php file in the form action:

<form method="get" action="yourfile.php">

Be warned though - this code is vulnerable to XSS attacks (google it) and shouldn't be used at all unless you want your site to be turned into a spam machine.

Re: Newbie: Email form to submitter...

Posted: Fri Mar 20, 2009 10:27 am
by jfavero
I have it already grabbing the "Contact.php" file with the following line on my form page:

<form name="contact_form" action="/policies/policies/contact.php" method="get">

However, I notice in my contact.php file, no where in it does it look for the corresponding field "contact_form"

I have it working on one page perfectly (without the grab email submitter puts in and sends email to them as well), however, on different servers, using what I think is the same code, only modified to get the fields I want, I get the following error (on my production server, I can't even get the page to load, and I think my problem is because I'm a different kind of server, but our tech guys don't have a clue), it's a site that is viewable by people who are linked into our network, so no public access (however, on our testing server on the other site, this code works perfectly fine :?:):

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for myemail@my.domain in D:\policies\policies\contact.php on line 24

Once again, here's the code (since modified to fit fields since yesterday :D

Code: Select all

 
<?
$subject="from ".$_GET['Submitter'];
$headers= "From: ".$_GET['email']."\n";
 $headers.='Content-type: text/html; charset=iso-8859-1';
mail("myemail@my.domain", $subject,  "
 
<html>
<head>
 <title>Thank you for submitting a media contact sheet. You will recieve a copy of this in your email shortly.</title>
</head>
<body>
<strong>Date:</strong> &nbsp;&nbsp;  ".$_GET['Date']."<br>
<strong>Division:</strong> &nbsp;&nbsp; ".$_GET['DivisionBureau']."<br>
<strong>Regional/Area/Unit Office:</strong> &nbsp;&nbsp; ".$_GET['Office']."<br>
<strong>Name of TV/Radio/Newspaper:</strong> &nbsp;&nbsp; ".$_GET['Media']."<br>
<strong>Name of Reporter:</strong> &nbsp;&nbsp; ".$_GET['Reportername']."<br>
<strong>Topic/Issue Prompting the Interview::</strong> &nbsp;&nbsp; ".$_GET['Topic']."<br>
<strong>Action(s)/Follow-up Required (if any)::</strong> &nbsp;&nbsp; ".$_GET['Action']."<br>
<strong>Your Name:</strong> &nbsp;&nbsp; ".$_GET['Submitter']."<br>
<strong>Topic:</strong> &nbsp;&nbsp; ".$_GET['email']."<br>
<strong>Phone:</strong> &nbsp;&nbsp; ".$_GET['Phone']."<br>
</body>
</html>" , $headers);
echo ("Your message was successfully sent!");
?>
<script>
    resizeTo(300, 300)
        //window.close()
</script>
Code from form page

Code: Select all

<form name="contact_form" action="/policies/policies/contact.php" method="get">
  <table width="520" align="left">
    <tr>
      <td width="102" align="left"><strong>Date:</strong></td>
      <td width="406"><input name="Date" type="text" class="form_1" id="Date" size="30"/></td>
    </tr>
    <tr>
      <td align="left"><strong>Division</strong></td>
      <td><select size="1" name="DivisionBureau">
          <option selected>Options</option>
          <option selected>Options</option>
        </select></td>
    </tr>
    <tr>
      <td align="left"><b>Regional/Area/Unit Office</b></td>
      <td><select size="1" name="Office">
          <option selected>N/A</option>
         <option selected>Options</option>
          <option selected>Options</option>
        </select></td>
    </tr>
    <tr>
      <td align="left"><b>Name of TV/Radio/Newspaper:</b></td>
      <td><input name="Media" type="text" class="form_1" id="Media" size="30"/></td>
      </tr>
    <tr>
        <td align="left"><strong>Name of Reporter</strong></td>
        <td><input name="Reportername" type="text" class="form_1" id="Reportername" size="30"/></td>
    </tr>
    <tr>
      <td align="left" valign="top" style="padding-top:3px"><b>Topic/Issue Prompting the Interview:</b></td>
      <td><label>
        <textarea name="Topic" cols="45" rows="10" class="form_2" id="Topic"></textarea>
      </label></td>
    </tr>
    <tr>
        <td align="left" valign="top" style="padding-top:3px"><b>Action(s)/Follow-up Required (if any):</b></td>
        <td><textarea name="Action" cols="45" rows="4" class="form_2" id="Action"></textarea></td>
    </tr>
    <tr>
      <td align="left"><strong>Your Name:</strong></td>
      <td><input name="Submitter" type="text" class="form_1" id="Submitter" size="30"/></td>
    </tr>
    <tr>
      <td valign="top"><strong>Your Email Address:</strong></td>
      <td><input name="email" type="text" class="form_1" id="email" size="30"/></td>
    </tr>
    <tr>
      <td valign="top"><b>Phone:</b></td>
      <td><input name="Phone" type="text" id="Phone" size="12" /></td>
    </tr>
    <tr>
        <td valign="top" colspan="2" align="center">
          <input type="image" onClick="reset(); return false;" src="/images/reset.gif" alt="Reset"/> 
        &nbsp;
        <input type="image" src="/images/submit.gif" onClick="submit();" target="_blank"/></td>
    </tr>
</table>
</form>
It's like I'm missing an included javascript file somewhere, or SOMETHING, but I just can't figure it out. The only different thing on this page from the one that's working is the <select size="1" name="DivisionBureau"> options... I don't have any click to select on the other pages.

Oh, and this is the page I grabbed it from... http://info.template-help.com/after_sal ... cle14.html