Copy link to clipboard
Copied
I'm trying to use a contact form that I had implemented on a different website. I copied over the form from the contact page, and then I also copied the necessary data from the mailer.php that the form submission uses.
This isn't the first time I have copied and used this form, I am fairly familiar with it. However, this is the first time that I have had to add quite a few more fields to it and I think that may be where my problem lies, not quite sure.
Anyways, here are the chunks of code.
this is located on the contact-us.php page:
<form method="post" action="mailer.php">
<input class="input" name="recipient" type="hidden" id="recipient" value="****@gmail.com" />
<input name="subject_prefix" type="hidden" id="subject_prefix" value="Contact Form: " />
<tr style="vertical-align:top">
<td style="text-align:right;">Name:</td>
<td><input class="input" type="text" name="name" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">City:</td>
<td><input class="input" type="text" name="city" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">State:</td>
<td><input class="input" type="text" name="state" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Zip Code:</td>
<td><input class="input" type="text" name="zipcode" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Closest Major City:</td>
<td><input class="input" type="text" name="majorcity" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">E-Mail:</td>
<td><input class="input" type="email" name="email" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Phone:</td>
<td><input class="input" type="tel" name="phone" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Contact Preference:</td>
<td><select class="input" size="1" name="contact_preference">
<option class="input" selected="selected">E-Mail</option>
<option class="input" >Telephone</option>
</select></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Contact Time:</td>
<td><select class="input" size="1" name="contact_time">
<option class="input" selected="selected">Morning</option>
<option class="input" >Afternoon</option>
<option class="input" >Evening</option>
</select></td>
</tr>
<tr style="vertical-align:top;">
<td style="text-align:right;">Message:</td>
<td><textarea class="textarea" style="resize:none;" rows="9" name="message" cols="33" ></textarea></td>
</tr>
<tr style="vertical-align:top">
<td></td>
<td><input class="submit" type="submit" value=" SUBMIT " name="submit" /></td>
</tr>
</form>
then on the mailer.php page I have:
<?php
$subject = $subject_prefix;
$body = "From: " . $name . "\n";
$body .= "----------------------------------\n";
$body .= "City: " . $city . "\n";
$body .= "----------------------------------\n";
$body .= "State: " . $state . "\n";
$body .= "----------------------------------\n";
$body .= "Zip Code: " . $zipcode . "\n";
$body .= "----------------------------------\n";
$body .= "Major City: " . $majorcity . "\n";
$body .= "----------------------------------\n";
$body .= "Email: " . $email . "\n";
$body .= "----------------------------------\n";
$body .= "Phone Number: " . $phone . "\n";
$body .= "----------------------------------\n";
$body .= "Contact Preference: " . $contact_preference . "\n";
$body .= "----------------------------------\n";
$body .= "Contact Time: " . $contact_time . "\n";
$body .= "----------------------------------\n";
$body .= "Message: \n" . $message . "\n";
$header = "From: \"" . $name . "\" <" . $email . ">\n";
if( mail($recipient, $subject, $body, $header) ){
echo "The form you entered has been submitted. Thank you, $name, for your interest in **** ";
echo "Contact <a href=\"mailto:****@gmail.com\">****</a> if you would like further assistance.";
} else {
echo "There was an error sending the data.<br /> ";
echo "Please contact **** here at <a href=\"mailto:****@gmail.com\">****@gmail.com</a> with your information.";
}
?>
it consistenly throws back the else error, but as far as I can tell, everything is there that should allow the if statement to succede.
Please let me know if you see what I am doing wrong.
Copy link to clipboard
Copied
Please show us the entire php page. The snippet you posted does not include the part where your variables are populated.
Copy link to clipboard
Copied
cantact page is
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
<meta name="generator" content="4.0.557.204"/>
<title>Contact Us</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/site_global.css?89652228"/>
<link rel="stylesheet" type="text/css" href="css/master_a-master.css?3773353120"/>
<link rel="stylesheet" type="text/css" href="css/contact-us.css?4271347313" id="pagesheet"/>
<!-- Other scripts -->
<script type="text/javascript">
document.documentElement.className += ' js';
</script>
</head>
<body>
<div class="clearfix" id="page"><!-- column -->
<div class="position_content" id="page_position_content">
<div class="colelem" id="u187"><!-- image -->
<img class="block" id="u187_img" src="images/top_bgr.jpg" alt="" width="1024" height="92"/>
</div>
<ul class="MenuBar clearfix colelem" id="menuu66"><!-- row -->
<li class="MenuItemContainer clearfix grpelem" id="u167"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu rounded-corners clearfix colelem" id="u170" href="index.html"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u172-4"><!-- content --><p>Our Firm</p></div></a>
</li>
<li class="MenuItemContainer clearfix grpelem" id="u141"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu rounded-corners clearfix colelem" id="u144" href="process.html"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u146-4"><!-- content --><p>Process</p></div></a>
</li>
<li class="MenuItemContainer clearfix grpelem" id="u154"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu rounded-corners clearfix colelem" id="u157" href="events.html"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u159-4"><!-- content --><p>Events</p></div></a>
</li>
<li class="MenuItemContainer clearfix grpelem" id="u180"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu MuseMenuActive rounded-corners clearfix colelem" id="u183" href="contact-us.php"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u185-4"><!-- content --><p>Contact Us</p></div></a>
</li>
</ul>
<div class="colelem" id="u286"><table width="100%" style="margin-left:40px;">
<!--Contact form here-->
<form method="post" action="mailer.php">
<input class="input" name="recipient" type="hidden" id="recipient" value="****@gmail.com" />
<input name="subject_prefix" type="hidden" id="subject_prefix" value="Contact Form: " />
<tr style="vertical-align:top">
<td style="text-align:right;">Name:</td>
<td><input class="input" type="text" name="name" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">City:</td>
<td><input class="input" type="text" name="city" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">State:</td>
<td><input class="input" type="text" name="state" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Zip Code:</td>
<td><input class="input" type="text" name="zipcode" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Closest Major City:</td>
<td><input class="input" type="text" name="majorcity" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">E-Mail:</td>
<td><input class="input" type="email" name="email" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Phone:</td>
<td><input class="input" type="tel" name="phone" size="30" /></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Contact Preference:</td>
<td><select class="input" size="1" name="contact_preference">
<option class="input" selected="selected">E-Mail</option>
<option class="input" >Telephone</option>
</select></td>
</tr>
<tr style="vertical-align:top">
<td style="text-align:right;">Contact Time:</td>
<td><select class="input" size="1" name="contact_time">
<option class="input" selected="selected">Morning</option>
<option class="input" >Afternoon</option>
<option class="input" >Evening</option>
</select></td>
</tr>
<tr style="vertical-align:top;">
<td style="text-align:right;">Message:</td>
<td><textarea class="textarea" style="resize:none;" rows="9" name="message" cols="33" ></textarea></td>
</tr>
<tr style="vertical-align:top">
<td></td>
<td><input class="submit" type="submit" value=" SUBMIT " name="submit" /></td>
</tr>
</form>
</table></div>
<div class="verticalspacer"></div>
<div class="clearfix colelem" id="pu198"><!-- group -->
<div class="grpelem" id="u198"><!-- image -->
<img class="block" id="u198_img" src="images/footer.png" alt="" width="1024" height="99"/>
</div>
<div class="clearfix grpelem" id="u282-4"><!-- content -->
<p>© All rights reserved. 2012. Privacy policy | Terms of use</p>
</div>
</div>
</div>
</div>
<div class="preload_images">
<img class="preload" src="images/m1m.jpg" alt=""/>
</div>
<!-- JS includes -->
<script type="text/javascript">
if (document.location.protocol != 'https:') document.write('\x3Cscript src="http://musecdn2.businesscatalyst.com/scripts/4.0/jquery-1.8.3.min.js" type="text/javascript">\x3C/script>');
</script>
<script type="text/javascript">
window.jQuery || document.write('\x3Cscript src="scripts/jquery-1.8.3.min.js" type="text/javascript">\x3C/script>');
</script>
<script src="scripts/museutils.js?4215913851" type="text/javascript"></script>
<script src="scripts/jquery.musemenu.js?3888647712" type="text/javascript"></script>
<script src="scripts/jquery.watch.js?4199601726" type="text/javascript"></script>
<!-- Other scripts -->
<script type="text/javascript">
Muse.Utils.addSelectorFn('body', Muse.Utils.transformMarkupToFixBrowserProblemsPreInit);/* body */
Muse.Utils.addSelectorFn('body', Muse.Utils.prepHyperlinks); /* body */
Muse.Utils.addSelectorFn('.MenuBar', function(elem) { return $(elem).museMenu(); });/* unifiedNavBar */
Muse.Utils.addSelectorFn('body', function() { Muse.Utils.fullPage('#page'); }); /* 100% height page */
Muse.Utils.addSelectorFn('body', Muse.Utils.showWidgetsWhenReady);/* body */
Muse.Utils.addSelectorFn('body', Muse.Utils.transformMarkupToFixBrowserProblems);/* body */
</script>
</body>
</html>
mailer page is
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
<meta name="generator" content="4.0.557.204"/>
<title>Contact Us</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/site_global.css?89652228"/>
<link rel="stylesheet" type="text/css" href="css/master_a-master.css?3773353120"/>
<link rel="stylesheet" type="text/css" href="css/contact-us.css?4271347313" id="pagesheet"/>
<!-- Other scripts -->
<script type="text/javascript">
document.documentElement.className += ' js';
</script>
</head>
<body>
<div class="clearfix" id="page"><!-- column -->
<div class="position_content" id="page_position_content">
<div class="colelem" id="u187"><!-- image -->
<img class="block" id="u187_img" src="images/top_bgr.jpg" alt="" width="1024" height="92"/>
</div>
<ul class="MenuBar clearfix colelem" id="menuu66"><!-- row -->
<li class="MenuItemContainer clearfix grpelem" id="u167"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu rounded-corners clearfix colelem" id="u170" href="index.html"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u172-4"><!-- content --><p>Our Firm</p></div></a>
</li>
<li class="MenuItemContainer clearfix grpelem" id="u141"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu rounded-corners clearfix colelem" id="u144" href="process.html"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u146-4"><!-- content --><p>Process</p></div></a>
</li>
<li class="MenuItemContainer clearfix grpelem" id="u154"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu rounded-corners clearfix colelem" id="u157" href="events.html"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u159-4"><!-- content --><p>Events</p></div></a>
</li>
<li class="MenuItemContainer clearfix grpelem" id="u180"><!-- vertical box -->
<a class="nonblock nontext MenuItem MenuItemWithSubMenu MuseMenuActive rounded-corners clearfix colelem" id="u183" href="contact-us.php"><!-- horizontal box --><div class="MenuItemLabel NoWrap clearfix grpelem" id="u185-4"><!-- content --><p>Contact Us</p></div></a>
</li>
</ul>
<div class="colelem" id="u286"><table width="100%" style="margin-left:40px;">
<?php
$subject = $subject_prefix;
$body = "From: " . $name . "\n";
$body .= "----------------------------------\n";
$body .= "City: " . $city . "\n";
$body .= "----------------------------------\n";
$body .= "State: " . $state . "\n";
$body .= "----------------------------------\n";
$body .= "Zip Code: " . $zipcode . "\n";
$body .= "----------------------------------\n";
$body .= "Major City: " . $majorcity . "\n";
$body .= "----------------------------------\n";
$body .= "Email: " . $email . "\n";
$body .= "----------------------------------\n";
$body .= "Phone Number: " . $phone . "\n";
$body .= "----------------------------------\n";
$body .= "Contact Preference: " . $contact_preference . "\n";
$body .= "----------------------------------\n";
$body .= "Contact Time: " . $contact_time . "\n";
$body .= "----------------------------------\n";
$body .= "Message: \n" . $message . "\n";
$header = "From: \"" . $name . "\" <" . $email . ">\n";
if( mail($recipient, $subject, $body, $header) ){
echo "The form you entered has been submitted. Thank you, $name, for your interest in ****. ";
echo "Contact <a href=\"mailto:****@gmail.com\">****</a> if you would like further assistance.";
} else {
echo "There was an error sending the data.<br /> ";
echo "Please contact **** here at <a href=\"mailto:j****@gmail.com\">****@gmail.com</a> with your information.";
}
?>
</table></div>
<div class="verticalspacer"></div>
<div class="clearfix colelem" id="pu198"><!-- group -->
<div class="grpelem" id="u198"><!-- image -->
<img class="block" id="u198_img" src="images/footer.png" alt="" width="1024" height="99"/>
</div>
<div class="clearfix grpelem" id="u282-4"><!-- content -->
<p>© All rights reserved. 2012. Privacy policy | Terms of use</p>
</div>
</div>
</div>
</div>
<div class="preload_images">
<img class="preload" src="images/m1m.jpg" alt=""/>
</div>
<!-- JS includes -->
<script type="text/javascript">
if (document.location.protocol != 'https:') document.write('\x3Cscript src="http://musecdn2.businesscatalyst.com/scripts/4.0/jquery-1.8.3.min.js" type="text/javascript">\x3C/script>');
</script>
<script type="text/javascript">
window.jQuery || document.write('\x3Cscript src="scripts/jquery-1.8.3.min.js" type="text/javascript">\x3C/script>');
</script>
<script src="scripts/museutils.js?4215913851" type="text/javascript"></script>
<script src="scripts/jquery.musemenu.js?3888647712" type="text/javascript"></script>
<script src="scripts/jquery.watch.js?4199601726" type="text/javascript"></script>
<!-- Other scripts -->
<script type="text/javascript">
Muse.Utils.addSelectorFn('body', Muse.Utils.transformMarkupToFixBrowserProblemsPreInit);/* body */
Muse.Utils.addSelectorFn('body', Muse.Utils.prepHyperlinks); /* body */
Muse.Utils.addSelectorFn('.MenuBar', function(elem) { return $(elem).museMenu(); });/* unifiedNavBar */
Muse.Utils.addSelectorFn('body', function() { Muse.Utils.fullPage('#page'); }); /* 100% height page */
Muse.Utils.addSelectorFn('body', Muse.Utils.showWidgetsWhenReady);/* body */
Muse.Utils.addSelectorFn('body', Muse.Utils.transformMarkupToFixBrowserProblems);/* body */
</script>
</body>
</html>
Copy link to clipboard
Copied
Your mail.php does not include code to assign the posted values to the variables. For example, you have:
$subject = $subject_prefix;
but nothing in the php script assigns the posted form value to $subject_prefix. It appears you missed that part when you copied and pasted from the other scripts.
Copy link to clipboard
Copied
does this line of code not do that?
<input name="subject_prefix" type="hidden" id="subject_prefix" value="Contact Form: " />
Copy link to clipboard
Copied
No. That is a form field. Your php script must then get the value from the form fields from the POST array and assign it to the local variables.
http://www.w3schools.com/php/php_forms.asp
You said you copied the code from a working site. Carefully check the code again and see how this is being done.
Copy link to clipboard
Copied
$subject = $subject_prefix . $inquiry;
$body = "From: " . $name . "\n";
$body .= "----------------------------------\n";
$body .= "E-Mail: " . $email . "\n";
$body .= "----------------------------------\n";
$body .= "Phone Number: " . $phone . "\n";
$body .= "----------------------------------\n";
$body .= "Contact Preference: " . $contact_preference . "\n";
$body .= "----------------------------------\n";
$body .= "Company: " . $company . "\n";
$body .= "----------------------------------\n";
$body .= "Inquiry: $subject \n";
$body .= "----------------------------------\n";
$body .= "Message: \n" . $message . "\n";
$header = "From: \"" . $name . "\" <" . $email . ">\n";
is the mailer from the original site. i had removed the subject field with the name inquery from the form so i removed that frm the first line. only thing i can think of that messed things up.
ill take a look at that link. thanks for the assistance
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more