Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Contact Form - error message
Old 03-17-2009, 08:55 PM PHP Contact Form - error message
Junior Talker

Posts: 2
Name: Ashley
Trades: 0
I've done as much through Google as I can for now, so I need help. I've done html and some javascript, but this is my first time using php. I have tried two different versions adapted to my form, but can't get either of them to work. Thanks!!

-Ashley

HTML Code:
  <form id="form1" name="form1" method="post" action="mailer.php" enctype="text/plain">
            
          <p><label class="formelement">Name</label>
            <input class="textbox" name="Name" type="text" maxlength="40" size="40"/>
             </p>
            
          <p><label class="formelement">Company</label>
            <input class="textbox" name="Company" type="text" maxlength="50" size="40"/>
          </p>
            
          <p>
            <label class="formelement">City</label>
            <input class="textbox" name="City" type="text" maxlength="40" size="40"/>
             </p>
            
          <p>
               <label class="formelement">State</label>
            <input class="textbox" name="State" type="text" maxlength="40" size="40"/>
          </p>
            
          <p><label class="formelement">Phone</label>
            <input class="textbox" name="Phone" type="text" maxlength="40" size="40"/>
             </p>

          <p><label class="formelement">Email</label>
            <input class="textbox" name="Email" type="text" maxlength="40" size="40"/>
             </p>

          <p><label class="formelement">Comments</label>
            <textarea name="Comments" cols="30" rows="10" wrap="virtual"></textarea>
          </p>
          
          <p>
            <label class="formelement">Where did you hear about us?</label>
            <select name="Source" id="info1">
                <option class="dropdown" value="" selected="selected">Select</option>
                <option class="dropdown" value="tradeshow">Tradeshow</option>
                <option class="dropdown" value="ad">Ad</option>
                <option class="dropdown" value="internet">Internet</option>
                <option class="dropdown" value="referral">Referral</option>
                <option class="dropdown" value="in store">In Store</option>
                <option class="dropdown" value="other">Other</option>
              </select>
          </p>
            
          <p><br />
            <label class="formelement">&nbsp;</label>
              <input type="submit" value="Send" name="submit"/>
              &nbsp;&nbsp;
              <input type="reset" value="Reset" name="reset"/>
          </p>
</form>
PHP Version 1
PHP Code:
<?php
if(isset($_POST['submit'])) 
    {
    
$to="art.vessel@gmail.com";
    
$subject="Online Inquiry";
    
$business_field=$_POST['business'];
    
$name_field=$_POST['name'];
    
$city_field=$_POST['city'];
    
$state_field=$_POST['state'];
    
$phone_field=$_POST['phone'];
    
$email_field=$_POST['email'];
    
$comments=$_POST['comments'];
    
    
$source=$_POST['source'];
    
    
$body="From: $name_field\n At: $business_field\n City: $city_field\n State: $state_field\n Phone: $phone_field\n E-Mail: $email_field\n Comments:\n $comments Source: $source\n";
    
    echo 
"Form has been submitted to $to!";
    
mail($to$subject$body);
    } 
    
    else 
    {
    echo 
"Error! No data sent!";
    }
?>
PHP Version 2
PHP Code:
<?php
$to 
$_REQUEST['sendto'] ;
$from $_REQUEST['Email'] ;
$name $_REQUEST['Name'] ;
$headers "From: $from";
$subject "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"City"} = "City";
$fields{"State"} = "State";
$fields{"Phone"} = "Phone";
$fields{"Email"} = "Email";
$fields{"Comments"} = "Comments";
$fields{"Source"} = "Source";

$body "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 "From: art.vessel@gmail.com";
$subject2 "Thank you for contacting us";
$autoreply "Thank you for your interest in Vessel Drinkware. Somebody will get back to you as soon as possible.";

if(
$email == '') {print "Oops! You forgot to fill in your email! Please go back and fill in the field.";}
else {
if(
$name == '') {print "Oops! You forgot to fill in your name! Please go back and fill in the field.";}
else {
$send mail($to$subject$body$headers);
$send2 mail($from$subject2$autoreply$headers2);
if(
$send)
{
header"Location: http://www.vesseldrinkware.com/thankyou.html" );}
else
{print 
"We encountered an error sending your mail, please notify art.vessel@gmail.com"; }
}
}
?>
art.katri is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-18-2009, 01:06 AM Re: PHP Contact Form - error message
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Your first version uses small letters where there should be capital ones, in the form field's names (name => Names, city => City etc.) and also you changed the form name Company into business.

You second version checks if $email equals '', but the variable $email is never set (you use $from) so the check will always fail.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 03-18-2009, 04:15 AM Re: PHP Contact Form - error message
Skilled Talker

Posts: 54
Trades: 0
even though i am not very familiar with dynamics of php, i have never seen associative arrays declared and initialise the way you did it. what i know is that the curly brackets should be square brackets. and whenever i want to use an associative array i declared and initialised it at the same time.like below
PHP Code:
$fields=array("Name"=>"Name","Company"=>"Company","City"=>"City"); 
the above array initialisation continuous like that up to the number of elements you want.
kani alavi is offline
Reply With Quote
View Public Profile
 
Old 03-18-2009, 01:45 PM Re: PHP Contact Form - error message
Junior Talker

Posts: 2
Name: Ashley
Trades: 0
Thanks for your help, I tried editing those, but they still wouldn't work. I've done more reading online and understand a little bit more. I found a new form that seems simpler, and I'm actually getting it to send an email with no errors, though now I can't get it to send the content of the fields.

I know the array and the line to send the message are screwed up, but I can't figure it out. I don't exactly understand the first line starting with $MsgBody...

PHP Code:
<?php
$SendFrom
="Form Feedback <art.vessel@gmail.com>";
$SendTo="art.vessel@gmail.com";
$SubjectLine="Feedback Submission";
$ThanksURL="thankyou.html";
$Field = array("Name"=>Name,"Company"=>Company,"City"=>City,"State"=>State,"Phone"=>Phone,"Email"=>Email,"Comments"=>Comments,"Source"=>Source);
$MsgBody "We have received the following information:\n\n"; foreach($Field as $a=>$b){ $MsgBody .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}
$MsgBody=htmlspecialchars($MsgBodyENT_NOQUOTES);
mail($SendTo$SubjectLine$MsgBody"From: $SendFrom");
header("Location: $ThanksURL");
?>
HTML Code:
<form id="form1" name="form1" method="post" action="form.php" enctype="text/plain">

<p><label class="formelement">Name</label>
<input class="textbox" name="Name" type="text" maxlength="40" size="40"/>
</p>

<p><label class="formelement">Company</label>
<input class="textbox" name="Company" type="text" maxlength="50" size="40"/>
</p>

<p>
<label class="formelement">City</label>
<input class="textbox" name="City" type="text" maxlength="40" size="40"/>
</p>

<p>
<label class="formelement">State</label>
<input class="textbox" name="State" type="text" maxlength="40" size="40"/>
</p>

<p><label class="formelement">Phone</label>
<input class="textbox" name="Phone" type="text" maxlength="40" size="40"/>
</p>

<p><label class="formelement">Email</label>
<input class="textbox" name="Email" type="text" maxlength="40" size="40"/>
</p>

<p><label class="formelement">Subject</label>
<input class="textbox" name="Subject" type="text" maxlength="40" size="40"/>
</p>

<p><label class="formelement">Message</label>
<textarea name="Message" cols="30" rows="10" wrap="virtual"></textarea>
</p>

<p>
<label class="formelement">Where did you hear about us?</label>
<select name="Source" id="info1">
<option class="dropdown" value="" selected="selected">Select</option>
<option class="dropdown" value="tradeshow">Tradeshow</option>
<option class="dropdown" value="ad">Ad</option>
<option class="dropdown" value="internet">Internet</option>
<option class="dropdown" value="referral">Referral</option>
<option class="dropdown" value="in store">In Store</option>
<option class="dropdown" value="other">Other</option>
</select>
</p>

<p><br />
<label class="formelement">&nbsp;</label>
<input type="submit" value="send" name="submit"/>
&nbsp;&nbsp;
<input type="reset" value="reset" name="reset"/>
</p>
</form>

Last edited by art.katri; 03-18-2009 at 09:28 PM..
art.katri is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Contact Form - error message
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21219 seconds with 12 queries