Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: html form to php email form

  1. #1
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default html form to php email form

    I need help changing my html form entries to php mail. Their seems to be some problem with getting the submitted form into the php file and then emailing it to me. I repeatedly have gotten emails from the php file, but their is no body to the email.

    HTML Code:
    <form action="sendmail.php" method="post" enctype="application/x-www-form-urlencoded" name="Application" target="_blank" id="Application">
        <table width="625" height="691" border="0">
          <tr>
            <td width="207"><label>
            <div align="right">Name:</div></td>
            <td width="408"><label>
              <input type="text" name="name" id="name" />
              <br />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Address:</div></td>
            <td><label>
              <input type="text" name="address" id="address" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Address 2:</div></td>
            <td><label>
              <input type="text" name="address2" id="address2" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">City:</div></td>
            <td><label>
              <input type="text" name="city" id="city" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">State:</div></td>
            <td><label>
              <select name="state" size="1" id="state">
                <option value="AK">AK</option>
    			<option value="AL">AL</option>
    			<option value="AR">AR</option>
    			<option value="AZ">AZ</option>
    			<option value="CA">CA</option>
    			<option value="CO">CO</option>
    			<option value="CT">CT</option>
    			<option value="DC">DC</option>
    			<option value="DE">DE</option>
    			<option value="FL">FL</option>
    			<option value="GA">GA</option>
    			<option value="HI">HI</option>
    			<option value="IA">IA</option>
    			<option value="ID">ID</option>
    			<option value="IL">IL</option>
    			<option value="IN">IN</option>
    			<option value="KS">KS</option>
    			<option value="KY">KY</option>
    			<option value="LA">LA</option>
    			<option value="MA">MA</option>
    			<option value="MD">MD</option>
    			<option value="ME">ME</option>
    			<option value="MI">MI</option>
    			<option value="MN">MN</option>
    			<option value="MO">MO</option>
    			<option value="MS">MS</option>
    			<option value="MT">MT</option>
    			<option value="NC">NC</option>
    			<option value="ND">ND</option>
    			<option value="NE">NE</option>
    			<option value="NH">NH</option>
    			<option value="NJ">NJ</option>
    			<option value="NM">NM</option>
    			<option value="NV">NV</option>
    			<option value="NY">NY</option>
    			<option value="OH">OH</option>
    			<option value="OK">OK</option>
    			<option value="OR">OR</option>
    			<option value="PA">PA</option>
    			<option value="RI">RI</option>
    			<option value="SC">SC</option>
    			<option value="SD">SD</option>
    			<option value="TN">TN</option>
    			<option value="TX">TX</option>
    			<option value="UT">UT</option>
    			<option value="VA">VA</option>
    			<option value="VT">VT</option>
    			<option value="WA">WA</option>
    			<option value="WI">WI</option>
    			<option value="WV">WV</option>
    			<option value="WY">WY</option>
              </select>
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Zip Code:
            </div></td>
            <td><label>
              <input type="text" name="zipcode" id="zipcode" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">*Cell Phone:</div></td>
            <td><label>
              <input type="text" name="cellphone" id="cellphone" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">*Email:</div></td>
            <td><label>
              <input type="text" name="email" id="email" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Birth Date:</div></td>
            <td><label>
              <input type="text" name="birthdate" id="birthdate" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Ethnicity:</div></td>
            <td><label>
              <input type="text" name="ethnicity" id="ethnicity" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Height:</div></td>
            <td><label>
              <input type="text" name="height" id="height" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Hair Color:</div></td>
            <td><label>
              <input type="text" name="haircolor" id="haircolor" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Body Type:</div></td>
            <td><label>
              <input type="text" name="bodytype" id="bodytype" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Weight:</div></td>
            <td><label>
              <input type="text" name="weight" id="weight" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right">Previous Modeling Experience (if any):</div></td>
            <td><label>
              <textarea name="experience" cols="50" id="experience"></textarea>
            </label></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><div align="right">*Required fields</div></td>
            <td><input type="submit" name="Submit" id="Submit" value="Apply" /></td>
          </tr>
        </table>
        <label><br />
        </label>
      </form>
    PHP Code:
    <?php
      $to
    '_@gmail.com';
      
      if(
    count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
      
      
    $subject'Application';
      
    $from'Website';
      
    $name $_POST["name"] ;
      
    $address $_POST["address"] ;
      
    $address2 $_POST["address2"] ;
      
    $city $_POST["city"] ;
      
    $state $_POST["state"] ;
      
    $zipcode $_POST["zipcode"] ;
      
    $cellphone $_POST["cellphone"] ;
      
    $email $_POST["email"] ;
      
    $birthdate $_POST["birthdate"] ;
      
    $ethnicity $_POST["ethnicity"] ;
      
    $height $_POST["height"] ;
      
    $haircolor $_POST["haircolor"] ;
      
    $bodytype $_POST["bodytype"] ;
      
    $weight $_POST["weight"] ;
      
    $experience $_POST["experience"] ;
      
    $bodystripslashes ("name" $name "address" $address "address2" $address2 "city" $city "state" $state "zipcode" $zipcode "cellphone" $cellphone "email" $email "birthdate" $birthdate "ethnicity" $ethnicity "height" $height "haircolor" $haircolor "bodytype" $bodytype "weight" $weight "experience" $experience) ;

      
    mail$to$subject$body$from );
    ?><title>sendmail.php</title>

    Thank you for contacting us! We will be in touch with you very soon.
    Thank you in advance for your assistance, I have been at this for 8 hours and have given up lol.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    First thing you might want to try in the debugging process is to see if those variables contain any values. For instance, using a die() statement right after the body variable is assigned, to see if there is any data in it.

    Try using
    PHP Code:
    die(print_r($_POST)); 
    in the PHP file, and see what values are in there.

    The code looks fine, so perhaps doing this will shed some light on what's happening.

  3. #3
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks! and More help!

    Thanks so much for your help! That glitch has now been fixed and it is working great now! In my search for trying to find a cure for my form issue I came across another concern. To my understanding my email address can be harvested and used by spammers. How would I go about avoiding this?

    Heres my updated script for those in need lol (and for assistance if those that are well-endowed would be so kind!
    PHP Code:
    <?php
      $to
    '_@gmail.com';
      
      if(
    count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
      
      
    $subject'Application';
      
    $from'Website';
      
    $name $_REQUEST['name'] ;
      
    $address $_REQUEST['address'] ;
      
    $address2 $_REQUEST['address2'] ;
      
    $city $_REQUEST['city'] ;
      
    $state $_REQUEST['state'] ;
      
    $zipcode $_REQUEST['zipcode'] ;
      
    $cellphone $_REQUEST['cellphone'] ;
      
    $email $_REQUEST['email'] ;
      
    $birthdate $_REQUEST['birthdate'] ;
      
    $ethnicity $_REQUEST['ethnicity'] ;
      
    $height $_REQUEST['height'] ;
      
    $haircolor $_REQUEST['haircolor'] ;
      
    $bodytype $_REQUEST['bodytype'] ;
      
    $weight $_REQUEST['weight'] ;
      
    $experience $_REQUEST['experience'] ;
      
    $bodystripslashes ('name ' $name ' address ' $address ' address2 ' $address2 ' city ' $city ' state ' $state ' zipcode ' $zipcode ' cellphone ' $cellphone ' email ' $email ' birthdate ' $birthdate ' ethnicity ' $ethnicity ' height ' $height ' haircolor ' $haircolor ' bodytype ' $bodytype ' weight ' $weight ' experience ' $experience) ;

      
    mail$to$subject$body$from );
    ?><title>sendmail.php</title>

    Thank you for submitting your application! We will be contacting you shortly!

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    If you have the email listed on your html page (i.e., action="mailto:myemail@domain.com" ) then this is a concern. However, if you only have the email on your server-side code, it will never be revealed to the typical user or bot (unless they've already hacked your server anyway, and then it's the least of your worries).

  5. #5
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I am not using a server because that seemed to be a little over my head at this point in time. I cam across a php tutorial that suggested that I ensure that my form is not sent to other emails.

    PHP Code:
    if ( preg_match"/[\r\n]/"$name ) || preg_match"/[\r\n]/"$email ) ) {
          
          [
    error.html]
          
          } 
    Though I plugged it into my code and it did not work. I instead received this error message: Parse error: syntax error, unexpected '[' in /home/p153j78n/public_html/sendmail.php on line 29

    I kind of know how to fix this but would like some assurance, because the r and n and / confuse me lol. Thanks!

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    PHP Code:
    [error.html
    Is causing that parse error.

    You need to do something with it. Do you want it to redirect to an error page called error.html?

    PHP Code:
    header("Location: error.html"); 
    If not, what do you want the script to do?

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by weiner769 View Post
    I am not using a server because that seemed to be a little over my head at this point in time...
    php runs on a server. it may not be your server, but it is on a server.

    under normal circumstances, php code (such as your $to= '_@gmail.com'; ) that is not echoed or printed or otherwise sent to the user's browser is inaccessable to everyday visitors and email harvesters.

    Edit: I believe the script you have above is used to prevent email header injection, so a bot/spammer can't use your form to send tons of email to everyone on the planet. By rejecting email submissions with line breaks, you make sure there's only one email address and not a big list.

    If (as seems to be the case) you are sending the email to a predetermined address (yours) and not to a user-submitted email address, this kind of script is not necessary.
    Last edited by traq; 02-03-2010 at 01:30 AM.

  8. #8
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That is exactly what I am doing! That clears it up. Thanks for your time.

  9. #9
    Join Date
    Mar 2008
    Location
    Greenville SC USA
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I am having a php email form issue as well. I hope it's okay that I piggy-back this thread.
    This is my first time trying to use a php email form and I am a novice so please bear with me.

    Every time I try to send a test email, I'm just getting a blank page.

    HTML FORM ON PAGE:

    Code:
    <form method="post" action="contact.php">
    			<div>
    				
    				<p>
    					<label for="input-1">Your Name</label><br/>
    					<input type="text" name="input-1" id="input-1" class="text" />
    				</p>
                            <p>
    					<label for="input-2">Your Email</label><br/>
    					<input type="text" name="input-2" id="input-2" class="text" />
    				</p>
                            <p>
    					<label for="input-3">Your Website</label><br/>
    					<input type="text" name="input-3" id="input-3" class="text" />
    				</p>
                            <p>
    					<label>Want to Affiliate?</label><br/>
    					<input type="radio" name="input-4" id="input-4" /> <label for="input-4" class="radio">Yes</label> <input type="radio" name="input-5" id="input-5" /> <label for="input-5" class="radio">No</label>
    				</p>
    				<p>
    					<label for="input-6">Comment</label><br/>
    					<textarea name="input-6" id="input-6" rows="10" cols="90"></textarea>
    				</p>
    					<input type="submit" value="Send" class="button"/>
    			</div>			
    			</form>
    CONTACT.PHP FORM ON SERVER

    Code:
    <?php 
    $to = "_@_____.com"; 
    $subject = "Contact Me"; 
    $input-1 = $_REQUEST['input-1'];
    $input-2 = $_REQUEST['input-2']; 
    $input-3 = $_REQUEST['input-3']; 
    $input-4 = $_REQUEST['input-4']; 
    $input-5 = $_REQUEST['input-5']; 
    $input-6 = $_REQUEST['input-6'];
    $headers = "From: $input-2";   
    $sent = mail($to, $subject, $input-1, $input-2, $input-3, $input-4, $input-5, $input-6); 
    if($sent)
    {print "Your mail was sent successfully"; }
    else
    {print "We encountered an error sending your mail"; }
    ?>
    SCREENSHOT OF FORM:



    SCREENSHOT OF SUBMIT RESULTS:



    As you can see it is calling the php form but not sending the email or displaying results to end user.
    I've been using this site and this site as my references and after two days, cannot figure out what I'm doing wrong. Any guidance is very much appreciated. Thank you!

  10. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The comma designates other attributes of the mail function try this.

    http://php.net/manual/en/function.mail.php

    PHP Code:
    <?php 
    $to 
    "_@_____.com"
    $subject "Contact Me"
    $input-$_REQUEST['input-1'];
    $input-$_REQUEST['input-2']; 
    $input-$_REQUEST['input-3']; 
    $input-$_REQUEST['input-4']; 
    $input-$_REQUEST['input-5']; 
    $input-$_REQUEST['input-6'];
    $headers "From: $input-2";   
    $body $input-$input-$input-$input-$input-$input-6;
    $sent mail($to$subject$body); 
    if(
    $sent)
    {print 
    "Your mail was sent successfully"; }
    else
    {print 
    "We encountered an error sending your mail"; }
    ?>
    Corrections to my coding/thoughts welcome.

  11. The Following User Says Thank You to bluewalrus For This Useful Post:

    CrystalSC (02-05-2010)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •