Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailing Forms 5

Status
Not open for further replies.

nofx1728

Technical User
Jan 26, 2006
65
US
Sorry, I have no experience with php, and I'm kind of handcuffed here. In the past I've always used server scripts to process and send my forms to an email address. However, that option is not available for this project. I have a few different forms already created on my site. What I'm looking for is a php script that can process the forms on my website, and then send them to a desired email address. Can someone please help me out?

Thank you,

nofx1728
 
Have looked at the [blue]mail()[/blue] function in the PHP online manual.

Other than, there is no magical way to send emails without making use of the server. Unless you change your form actions to action="mailto:whatever@wherever.com" of course this uses the installed mail client in the user's machine as opposed to your server.

And as not all users have mail clients configured it is not reliable.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I think you misunderstood me. I was using server scripts that were already made. I still want to use server technology, I just don't know how to build the script by myself.

thanks,

nofx1728
 
form fields arrive in php in either the $_GET or $_POST superglobal arrays (depending on the submission method).

you can just take the contents of those variables and email them eg:

Code:
<?php
if (isset($_POST['submit']) && $_POST['submit'] === "submit"){

 $to = "me@example.com";
 $from = "me@example.com";
 $subject = "form submission";
 $now = date("D, j F, Y at H:i:s");
 $body = <<<STR

a user submitted the name {$_POST['yourname']} to an online form on {$now}.

STR;
 mail($to, $subject, $body, $from."\r\n");
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Your name: <input type="text" name="yourname" /><br/>
<input type="submit" name="submit" value="submit" />
</form>
 
I want to apologize in advance for being so difficult. I'm sure you've probably answered the question in the simplest terms, but I just want to double check something real quick. Here is my form:

Code:
<form id="contactForm" name="contactForm" method="post" action="">
						<table width="450" border="0">
  <tr>
    <td width="210"><p class="mediumtext">Last Name:</p></td>
    <td width="230"><p>
      <input name="lastName" type="text" id="lastName" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">First Name:</p></td>
    <td><p>
      <input name="firstName" type="text" id="firstName" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Primary Street Address:</p></td>
    <td><p>
      <input name="addressOne" type="text" id="addressOne" size="28" />
    </p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><p>
      <input name="addressTwo" type="text" id="addressTwo" size="28" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">City:</p></td>
    <td><p>
      <input name="city" type="text" id="city" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">State:</p></td>
    <td><p>
      <input name="state" type="text" id="state" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Zip Code:</p></td>
    <td><p>
      <input name="textfield" type="text" size="28" maxlength="12" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Phone:</p></td>
    <td><p>
      <input name="phone" type="text" id="phone" size="28" maxlength="11" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Email Address</p></td>
    <td><p>
      <input name="email" type="text" id="email" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p>Comments/Questions:</p></td>
    <td><p><textarea name="comments" cols="28" rows="5" id="comments"></textarea>
    </p></td>
  </tr>
  <tr>
    <td colspan="2"><p><input name="receiveEmail" type="checkbox" value="receiveEmail" />
      <span class="mediumtext"> I am currently a member. </span></p></td>
    </tr>
  <tr>
    <td colspan="2"><p>&nbsp;</p>      <p class="center">
        <input type="submit" name="Submit" value="Submit" />
        <input name="reset" type="reset" id="reset" value="Reset" />
        </p></td>
    </tr>
</table>
</form>

The code from jpadie is like jiberish, thank you very much for the post though, it is much appreciated. I have no clue how to apply that to this form. As for your link dagger, can I just download that file, upload it to my server, and it will work with this type of form? Sorry again guys for being so difficult, I have no knowledge of php, been learning html, css, and flash first. Now I'm going to start focusing on server side scripts.

Thanks,

nofx1728
 
Ok, I made something up. I'm not sure if it's what you had in mind, but I think it is. Just put this in a file with a .php extension, and point to action of you form to it. The inline comments (anything with // in front of it) should explain what things do.

Code:
<?php
// This first part takes the form information and assigns it to variables
$fname = $_POST["firstName"];
$lname = $_POST["lastName"];
$addr1 = $_POST["addressOne"];
$addr2 = $_POST["addressTwo"];
$city = $_POST["city"];
$state = $_POST["state"];
$Mtext = $_POST["textfield"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$comments = $_POST["comments"];
$recEmail = $_POST["receiveEmail"];

// this is where you want to enter the e-mail address that the form information is being sent to.
$to = "me@example.com";
// this is what will apear in the "from" section of the e-mail. I have it set to the email in the form
$from = $email;
// here is the subject of the e-mail, currently set to "form submission"
$subject = "form submission";
$now = date("D, j F, Y at H:i:s");
// this is the body of the e-mail. You can format it however you want.
// In between the open an close brackets just write the email you want to send.
// use the varable names at the top, with the $ symbols.
$body = "
$fname $lname
Address:
$addr1 ($addr2) $city, $state
$phone

$Mtext

comment:
$comment
";

// This function sends the email
mail($to, $subject, $body, "from:".$from);
?>
 
Thanks everyone for all of your help. I was reading a bunch about php today from w3, and with your help it's starting to make some sense. It is much appreciated.

Thanks,

nofx1728
 
Can anyone tell me what I'm doing wrong? Here is my code for html and php.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"><!--[/URL] InstanceBegin template="/Templates/maintemplate.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Concerned Citizens of Indian River County - Contact Us</title>
<!-- InstanceEndEditable -->
<link href="concernedmain.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "[URL unfurl="true"]http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version[/URL]
=ShockwaveFlash";
      }
    }
  } 
}
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body onload="MM_CheckFlashVersion('7,0,19,0','Content on this page requires a newer version of Macromedia Flash Player. Do you want to download it now?');">
<div id="container"><!-- InstanceBeginEditable name="header" -->
	  <div id="header">
        <div id="flag"> </div>
	    <div id="rightflag"> </div>
    </div>
	  <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="side" -->
	  <div id="side">
        <div id="bottomflag"> </div>
	    <div id="leftside">
          <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.[/URL]
cab#version=
7,0,19,0" width="195" height="475" title="Concerned Citizens Menu">
            <param name="movie" value="assets/cc_menu.swf" />
            <param name="quality" value="high" />
            <embed src="assets/cc_menu.swf" quality="high" pluginspage="[URL unfurl="true"]http://www.macromedia.com/go/getflashplayer"[/URL] type="application/x-shockwave-flash" width="195" height="475"></embed>
          </object>
        </div>
      </div>
	  <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="content" -->
	  <div id="content">
        <div id="topcontent"> </div>
	    <div id="maincontent">
          <h1>Contact Us </h1>
	      <p class="center"><span class="keypoint">Corporate Office:</span></p>
		  <p class="center"><span class="mediumtext">4865 N. Highway A1A<br />
Vero Beach, FL 32963<br />
<a href="[URL unfurl="true"]http://www.mapquest.com/maps/map.adp?searchtype=address&amp;country=[/URL]
US&amp;addtohistory=&amp;searchtab=home&amp;formtype=address&amp;popflag=
0&amp;latitude=&amp;longitude=&amp;name=&amp;phone=&amp;level=&amp;cat=
&amp;address=4865+Highway+A1A&amp;city=Vero+Beach&amp;state=FL&amp;zipcode=
32963" target="_blank">Get Directions:</a><br />
		  Phone: 772-234-5230<br />
		  Fax: 772-234-5208<br />
		  <a href="mailto:info@ccirc.org">info@ccirc.org</a></span></p>
		  <p class="center"><span class="mediumtext"><a href="mailto:emmee@ccirc.org">Emmee Terry</a>, Executive Director</span></p>
		  		<div id="twocolumn">
			  <div id="newsletterform">
				<p class="center"><span class="keypointblue">INFORMATION REQUEST FORM</span></p>
					<p class="mediumtext">Please fill out the form below to request information or make comments. Please   also feel free to call our offices for more personalized service. </p>
					<form id="contactForm" name="contactForm" method="post" action="contactus.php">
						<table width="450" border="0">
  <tr>
    <td width="210"><p class="mediumtext">Last Name:</p></td>
    <td width="230"><p>
      <input name="lastName" type="text" id="lastName" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">First Name:</p></td>
    <td><p>
      <input name="firstName" type="text" id="firstName" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Primary Street Address:</p></td>
    <td><p>
      <input name="addressOne" type="text" id="addressOne" size="28" />
    </p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><p>
      <input name="addressTwo" type="text" id="addressTwo" size="28" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">City:</p></td>
    <td><p>
      <input name="city" type="text" id="city" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">State:</p></td>
    <td><p>
      <input name="state" type="text" id="state" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Zip Code:</p></td>
    <td><p>
      <input name="zipcode" type="text" id="zipcode" size="28" maxlength="12" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Phone:</p></td>
    <td><p>
      <input name="phone" type="text" id="phone" size="28" maxlength="12" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Email Address</p></td>
    <td><p>
      <input name="email" type="text" id="email" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p>Comments/Questions:</p></td>
    <td><p><textarea name="comments" cols="28" rows="5" id="comments"></textarea>
    </p></td>
  </tr>
  <tr>
    <td colspan="2"><p><input name="receiveEmail" type="checkbox" value="receiveEmail" />
      <span class="mediumtext"> I am currently a member. </span></p></td>
    </tr>
  <tr>
    <td colspan="2"><p>&nbsp;</p>      <p class="center">
        <input type="submit" name="Submit" value="Submit" />
        <input name="reset" type="reset" id="reset" value="Reset" />
        </p></td>
    </tr>
</table>
</form>
				</div>
				<p><img src="assets/spacer.gif" alt="spacer" width="1" height="1" /></p>
			</div>	
	    </div>
      </div>
	  <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="bottompage" -->
	  <div id="bottompage"> </div>
	  <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="footer" -->
		  <div id="footer">
            <p class="footer">© 2005 Copyright Concerned Citizens For the Future of Indian River County. All Rights Reserved.<br />
              4865 N. A1A | Vero Beach, FL 32963 | 772-234-5230 | Fax: 772-234-5208 | <a href="mailto: info@ccirc.org">info@ccirc.org</a> </p>
	      </div>
		  <!-- InstanceEndEditable --></div>
</body>
<!-- InstanceEnd --></html>

PHP Code - Used From Post above

Code:
<?php
// This first part takes the form information and assigns it to variables
$fname = $_POST["firstName"];
$lname = $_POST["lastName"];
$addr1 = $_POST["addressOne"];
$addr2 = $_POST["addressTwo"];
$city = $_POST["city"];
$state = $_POST["state"];
$zipcode = $_POST["zipcode"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$comments = $_POST["comments"];
$recEmail = $_POST["receiveEmail"];

// this is where you want to enter the e-mail address that the form information is being sent to.
$to = "nofx1728@bellsouth.net";
// this is what will apear in the "from" section of the e-mail. I have it set to the email in the form
$from = $email;
// here is the subject of the e-mail, currently set to "form submission"
$subject = "form submission";
$now = date("D, j F, Y at H:i:s");
// this is the body of the e-mail. You can format it however you want.
// In between the open an close brackets just write the email you want to send.
// use the varable names at the top, with the $ symbols.
$body = "
$fname $lname
Address:
$addr1 ($addr2) $city, $state
$phone

$zipcode

comment:
$comment

Received Email
$recEmail
";

// This function sends the email
mail($to, $subject, $body, "from:".$from);
?>

When I click on the submit button from my test site on bellsouth it sends me to a page that says:

The page cannot be displayed
The page you are looking for cannot be displayed because the page address is incorrect.

--------------------------------------------------------------------------------

Please try the following:

If you typed the page address in the Address bar, check that it is entered correctly.

Open the bellsouthpwp2.net home page and then look for links to the information you want.
HTTP 405 - Resource not allowed
Internet Information Services

--------------------------------------------------------------------------------

Technical Information (for support personnel)

More information:
Microsoft Support

Please help.

Thanks,

Nofx1728
 
error 405 is for method not allowed. indicating that the page or directory in which the page resides does not, at least, allow the POST method. the page is contactus.php

this may not be the end of the issue though: try including the fully qualified name of the contactus.php page in the form action ie.
and see whether you get the same result.

also check for an .htaccess file in that directory that may be intefering with the post.
 
Ok, I guess bellsouth didn't allow php scripts, which is why it was not displaying the next page. I changed it to a different host and tried it. I added this header("Location: below the mail($to, $subject, $body, "from:".$from); section, and when I click submit it transfers me to the correct page. However, it has been over an hour and the form submission has not come through to the email that I listed. Is there a way to make sure that the form is actually being emailed?

Thanks,

nofx1728
 
not without access to the mailserver logs, I suspect.

could you try changing this line
Code:
mail($to, $subject, $body, "from:".$from);
to
Code:
$result = mail($to, $subject, $body, "From:".$from."r\n");
if (!$result) {die("mail error");} else {header("Location: [URL unfurl="true"]http://www.dlfmedia.com/thankyou.html");}[/URL]

the main change here is to add a CRLF after the headers and to test whether there is anything wrong with the mail command itself.

you could try using phpmailer (it's on sourceforge) which has its own smtp class from which you will get better feedback on non-delivered mails.
 
I got the word "mail error" on a blank page. Not sure what I'm missing, or what I need to do.

Thanks,

nofx1728
 
is the smtp server properly configured in php.ini? or if you are using linux have is your MTA set in php.ini (usually in the directive sendmail_path or otherwise available to the script?

as i said - you can bypass these problems by using phpmailer.

check also that the POST variables are getting through as you expect them. you could do this by just trying a script of
Code:
<?php mail ("nofx1728@bellsouth.net", "subject of test mail", "body of test mail", "From: nofx1728@bellsouth.net\r\n"); ?>
 
I'm lost again. Like I said before I never tried anything before because godaddy provides the scripts. I don't even know what php.ini is. But the one I'm testing on is hosted by godaddy. Its windows based, not linux. I don't know what MTA is. I'm trying to go through phpmailer now. It talks about changing something in the .ini file so i'm trying to figure that out.

Thanks,

nofx1728
 
MTA - mail transfer agent
php.ini - the configuration file that tells php how to behave

you should not need to change php.ini at all to use phpmailer. so long as you know the hostname, username and password for your smtp server (user the SMTP option).

you can find out what is contained in your php.ini (or the effect of it) by running a script with just the following in it
Code:
<? phpinfo(); ?>
 
Alright, I can't figure out phpmailer because I don't have the smtp information, because this is being hosted by a person who hosts several different companies, so she can't give me any of the hosting information. So I tried several different things - 0 effective. I have no clue whats going on, but it can't be the php scripts, any other ideas? Here is what I've tried.

I downloaded this program from hotscripts.com - no success
Code:
<?php
# ----------------------------------------------------
# -----
# ----- This script was generated by the demo version of PHP-Form Wizard 1.2.6 on 9/6/2006 at 10:43:53 AM
# -----
# ----- [URL unfurl="true"]http://www.tools4php.com[/URL]
# -----
# ----------------------------------------------------
# -----
# ----- Many Features are available only in the Full version, to order please follow this link : 
# -----
# ----- http:// [URL unfurl="true"]www.tools4php.com/form-wizard/index.html[/URL] 
# -----
# ----------------------------------------------------


// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$subject = addslashes($_POST['subject']);
@$redirect = addslashes($_POST['redirect']);
@$lastName = addslashes($_POST['lastName']);
@$firstName = addslashes($_POST['firstName']);
@$addressOne = addslashes($_POST['addressOne']);
@$addressTwo = addslashes($_POST['addressTwo']);
@$city = addslashes($_POST['city']);
@$state = addslashes($_POST['state']);
@$zipcode = addslashes($_POST['zipcode']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$comments = addslashes($_POST['comments']);
@$receiveEmail = addslashes($_POST['receiveEmail']);

// Validation
if (strlen($lastName) == 0 )
{
header("Location: index.html");
exit;
}

if (strlen($firstName) == 0 )
{
header("Location: index.html");
exit;
}

if (strlen($addressOne) == 0 )
{
header("Location: index.html");
exit;
}

if (strlen($city) == 0 )
{
header("Location: index.html");
exit;
}

if (strlen($state) == 0 )
{
header("Location: index.html");
exit;
}

if (strlen($zipcode) == 0 )
{
header("Location: index.html");
exit;
}

if (strlen($email) == 0 )
{
header("Location: index.html");
exit;
}

//Sending Email to form owner
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "Form Submission";
$pfw_email_to = "nofx1728@bellsouth.net";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "subject: $subject\n"
. "redirect: $redirect\n"
. "lastName: $lastName\n"
. "firstName: $firstName\n"
. "addressOne: $addressOne\n"
. "addressTwo: $addressTwo\n"
. "city: $city\n"
. "state: $state\n"
. "zipcode: $zipcode\n"
. "phone: $phone\n"
. "email: $email\n"
. "comments: $comments\n"
. "receiveEmail: $receiveEmail\n"
. "This message was sent by the trial version of PHP-Form Wizard, To Get the full version please use this link: [URL unfurl="true"]http://tools4php.com/form-wizard/order.html";[/URL]
$result = @mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
//Available only in the full version
if (!$result) {die("mail error");} else {header("Location: [URL unfurl="true"]http://www.dlfmedia.com/thankyou.html");}[/URL]

?>

Tried adding the php to my html page, and saving it as a php file - no success.
Code:
<form id="contactForm" name="contactForm" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
					<input type="hidden" name="subject" value="Form Submission" /> 
<input type="hidden" name="redirect" value="thankyou.html" />
						<table width="450" border="0">
  <tr>
    <td width="210"><p class="mediumtext">Last Name:</p></td>
    <td width="230"><p>
      <input name="lastName" type="text" id="lastName" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">First Name:</p></td>
    <td><p>
      <input name="firstName" type="text" id="firstName" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Primary Street Address:</p></td>
    <td><p>
      <input name="addressOne" type="text" id="addressOne" size="28" />
    </p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><p>
      <input name="addressTwo" type="text" id="addressTwo" size="28" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">City:</p></td>
    <td><p>
      <input name="city" type="text" id="city" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">State:</p></td>
    <td><p>
      <input name="state" type="text" id="state" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Zip Code:</p></td>
    <td><p>
      <input name="zipcode" type="text" id="zipcode" size="28" maxlength="12" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Phone:</p></td>
    <td><p>
      <input name="phone" type="text" id="phone" size="28" maxlength="12" />
    </p></td>
  </tr>
  <tr>
    <td><p class="mediumtext">Email Address</p></td>
    <td><p>
      <input name="email" type="text" id="email" size="28" maxlength="40" />
    </p></td>
  </tr>
  <tr>
    <td><p>Comments/Questions:</p></td>
    <td><p><textarea name="comments" cols="28" rows="5" id="comments"></textarea>
    </p></td>
  </tr>
  <tr>
    <td colspan="2"><p><input name="receiveEmail" type="checkbox" value="receiveEmail" />
      <span class="mediumtext"> I am currently a member. </span></p></td>
    </tr>
  <tr>
    <td colspan="2"><p>&nbsp;</p>      <p class="center">
        <input type="submit" name="Submit" value="Submit" />
        <input name="reset" type="reset" id="reset" value="Reset" />
        </p></td>
    </tr>
</table>
</form>
<?php
if($_POST['do']=="send") {
	$recipient="nofx1728@bellsouth.net"; // Set your email here //
	$subject=$_POST['lastName'];
	$name=$_POST['firstName'];
	$email=$_POST['email'];
	$message=$_POST['comments'];
	$formsend=mail("$recipient", "$subject", "$message", "From: $name ($email)\r\nReply-to:$email");
	echo("Your message was successfully sent!");
}
?>

Tried doing this general code I got from a tutorial - no success.
Code:
<?php
   if ($_SERVER['REQUEST_METHOD']=="POST"){
      // In testing, if you get an Bad referer error
      // comment out or remove the next three lines
      if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
         !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
         die("Bad referer");
      $msg="Values submitted by the user:\n";
      foreach($_POST as $key => $val){
         if (is_array($val)){
            $msg.="Item: $key\n";
            foreach($val as $v){
               $v = stripslashes($v);
               $msg.="   $v\n";
            }
         } else {
            $val = stripslashes($val);
            $msg.="$key: $val\n";
         }
      }
      $recipient="nofx1728@bellsouth.net";
      $subject="Form submission";
      error_reporting(0);
      if (mail($recipient, $subject, $msg)){
         echo "<h1>Thank you</h1><p>Message successfully sent:</p>\n";
         echo nl2br($input);
      } else
         echo "An error occurred and the message could not be sent.";
   } else
      echo "Bad request method";
?>

And I've tried all the great options that were given to me on this forum - no success. LOL. I have no clue what I'm doing wrong. Does anyone have any idea how I can get this form to send (never thought it would be this difficult.)

FYI - I'm testing this with no success on a site being hosted by godaddy that accepts php. I've tried it on a test site on bellsouth.net. Is there another free test site that I can try it at?

Thanks

nofx1728
 
The thing finally worked, I don't know how. Then, I saved it as a new name and I'm getting an error: Parse error: parse error, unexpected T_VARIABLE in D:\hshome\cmechlin\test.ccirc.org\contactform.php on line 69

this is my code:

Code:
<?php
// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$lastName = addslashes($_POST['lastName']);
@$firstName = addslashes($_POST['firstName']);
@$addressOne = addslashes($_POST['addressOne']);
@$addressTwo = addslashes($_POST['addressTwo']);
@$city = addslashes($_POST['city']);
@$state = addslashes($_POST['state']);
@$zipcode = addslashes($_POST['zipcode']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$comments = addslashes($_POST['comments']);
@$receiveEmail = addslashes($_POST['receiveEmail']);

// Validation
if (strlen($lastName) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Last Name</font></p>");
}

if (strlen($firstName) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid First Name</font></p>");
}

if (strlen($addressOne) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Address</font></p>");
}

if (strlen($city) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid City</font></p>");
}

if (strlen($state) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid State</font></p>");
}

if (strlen($zipcode) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Zipcode</font></p>");
}

if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Email</font></p>");
}

//Sending Email to form owner
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "Form Submission Contact Us";
$pfw_email_to = "emmee@ccirc.org";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "lastName: $lastName\n"
. "firstName: $firstName\n"
. "addressOne: $addressOne\n"
. "addressTwo: $addressTwo\n"
. "city: $city\n"
. "state: $state\n"
. "zipcode: $zipcode\n"
. "phone: $phone\n"
. "email: $email\n"
. "comments: $comments\n"
. "receiveEmail: $receiveEmail\n"
$result = @mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
if (!$result) {die("mail error");} else {header("Location: [URL unfurl="true"]http://www.ccirc.org/thankyou.html");}[/URL]

?>


Anyone see anything wrong with that?

Thanks,

nofx1728
 
You are missing a semicolon here:

Code:
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "lastName: $lastName\n"
. "firstName: $firstName\n"
. "addressOne: $addressOne\n"
. "addressTwo: $addressTwo\n"
. "city: $city\n"
. "state: $state\n"
. "zipcode: $zipcode\n"
. "phone: $phone\n"
. "email: $email\n"
. "comments: $comments\n"
. "receiveEmail: $receiveEmail\n" [red]<<[/red][green] missing a semicolon "[blue];[/blue]" here to terminate the variable. $pfw_message;[/green]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top