Jump to content

Recommended Posts

Okay, I have created my Contact.php now and I have my Mailer.php file to do the mailing.  I have a few questions about my Mailer.php now.

 

<?php 
if(isset($_POST['submit'])) { 
$to = "admin@qwertytech.bounceme.net"; 
$subject = $_POST['EmailSubject']; 
$name_field = $_POST['SenderName']; 
$email_field = $_POST['SenderEmail']; 
$message = $_POST['ContactMessage']; 
$ip = @$REMOTE_ADDR;
$datetime = date('l dS \of F Y h:i:s A');
  
$body = "From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message"; 
  
echo "Data has been submitted to site Administrator!"; 
mail($to, $subject, $body); 
} else { 
echo "Please try again!"; 
} 
?> 

 

I was wanting to know if the $ip and $datetime is coded right....

 

Also,  what code would I have to add to put a copy of this Contact form to a database????

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/
Share on other sites

Regarding your question about saving a record in a database, I would suggest that you find a PHP-MySQL tutorial / guide and learn how to created database tables, connect to the database, insert data, receive data ect.. of course only if you do not already know :)

 

If someone posted the complete code to create the db table, connect and post data it would confuse you if you don't have any basic experience with databases :)

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/#findComment-259345
Share on other sites

Okay, so i have read the article that you reconmended....  that was very helpful. Thank you!  The only thing I have a question is, in the $sql command how do i insert multiple value into multiple fields?

 

<?php 
if(isset($_POST['submit']))
{ 
// database information 
   $host = 'localhost';       
   $user = 'admin'; 
   $password = 'password'; 
   $dbName = 'QWERTYTECH';

// connect and select the database 
   	   $conn = mysql_connect($host, $user, $password) or die(mysql_error()); 
       	   $db = mysql_select_db($dbName, $conn) or die(mysql_error());

// Information for EMAIL
   $to = "admin@qwertytech.bounceme.net"; 
   $subject = $_POST['EmailSubject']; 
   $name_field = $_POST['SenderName']; 
           $email_field = $_POST['SenderEmail']; 
   $message = $_POST['ContactMessage']; 
   $ip = $_SERVER['REMOTE_ADDR'];
   $datetime = date('l dS \of F Y h:i:s A');
  
   $body = "From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message"; 

   echo "Data has been submitted to site Administrator!"; 
   mail($to, $subject, $body);

   	// insert new entry into database 
      	   $sql = "insert into Contact (someField) values ('$newEntry')"; 
      	   $result = mysql_query($sql, $conn) or die(mysql_error());               
   	  
} 
else
{ 
   echo "Please try again!"; 
} 
?>

 

Are there suppost to be () around the $sql data?

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/#findComment-259368
Share on other sites

Okay, so i have created the following mailer.php page....

 

<?php 
if(isset($_POST['submit']))
{ 
// database information 
   $host = 'localhost';       
   $user = 'admin'; 
   $password = 'password'; 
   $dbName = 'newdb';

// connect and select the database 
   	   $conn = mysql_connect($host, $user, $password) or die(mysql_error()); 
                $db = mysql_select_db($dbName, $conn) or die(mysql_error());

// Information for EMAIL
   $to = "admin@mydomain.com"; 
   $subject = $_POST['EmailSubject']; 
   $name_field = $_POST['SenderName']; 
                $email_field = $_POST['SenderEmail']; 
   $message = $_POST['ContactMessage']; 
   $ip = $_SERVER['REMOTE_ADDR'];
   $datetime = date('l dS \of F Y h:i:s A');
  
   $body = 'From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message'; 

   // insert new entry into database 
                $sql = 'insert into Contact (Contact_Name, Contact_Email, Contact_Date, Contact_IP, Contact_Subject, Contact_Message)values ('$name_field', '$email_field', '$datetime', '$ip', '$subject', '$message')'; 
                $result = mysql_query($sql, $conn) or die(mysql_error());  

   echo 'Data has been submitted to site Administrator!'; 
   mail($to, $subject, $body);             
   	  
} 
else
{ 
   echo "Please try again!"; 
} 
?>

 

Whenever I submit the following mailer.php i get no emails..... What am I doing wrong?  I don't even get the 'Data has been submitted to site Administrator' or 'Please try again!'. 

 

Please someone help me.

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/#findComment-262226
Share on other sites

Contact.html

<form name="phpformmailer" action="mailer.php" align="center" method="post">
   <div align="center">
      <center>
         <table bgcolor="#F2F2F2" width="528" cellspacing="6">
            <tr>
      	  <td width="159"><strong>Contact Us</strong></td>
      	  <td width="349"><a href="index.html">Home</a> > <a href="contact.html">Conctact Us</a></td>
            </tr>
            <tr>
      	  <td align="right" width="159"><small>Your name:</small></td>
      	  <td width="349"><font face="Arial"><input class="inputc" size="29" name="name"></font></td>
            </tr>
            <tr>
      	  <td align="right" width="159"><font color="red" size="1">*</font><small> Your email address:</small></td>
      	  <td align="left" width="349"><font face="Arial"><input class="inputc" size="29" name="email"></font></td>
            </tr>
            <tr align="middle">
  <td align="right" width="159"><font color="red" size="1">*</font><small> Confirm email address:</small></td>
  <td width="349" align="left"><font face="Arial"><input class="inputc" size="29" name="email2"></font></td>
            </tr>
            <tr>
      	  <td align="right" width="159"><font color="red" size="1">*</font><small> Subject:</small></td>
      	  <td width="349"><font face="Arial"><input class="inputc" size="29" name="thesubject"></font></td>
            </tr>
            <tr>
      	  <td align="right" width="159"> <p><font color="#000080" size="1">*</font><small> Your request or query:</small></td>
               <td width="349"><textarea style="FONT-SIZE: 10pt" name="themessage" rows="7" cols="27"></textarea></td>
</tr>
<tr>
   <td width="159"></td>
   	   <td width="349">
                   <script language="JavaScript"><!--  
                      function validateForm() 
	{
		   var okSoFar=true
		   with (document.phpformmailer)
		      {
	         var foundAt = email.value.indexOf("@",0)
	         if (foundAt < 1 && okSoFar)
	            {
    			   okSoFar = false
    			   alert ("Please enter a valid email address.")
    			   email.focus()
  			}
  		         var e1 = email.value
  	  	         var e2 = email2.value
  	                      if (!(e1==e2) && okSoFar)
  			{
    			   okSoFar = false
    			   alert ("Email addresses you entered do not match.  Please re-enter.")
    			   email.focus()
  			}
  		         if (thesubject.value=="" && okSoFar)
  			{
    			   okSoFar=false
    			   alert("Please enter the subject.")
    			   thesubject.focus()
  			}
  	                       if (themessage.value=="" && okSoFar)
  			{
    			   okSoFar=false
    			   alert("Please enter the details for your enquiry.")
    			   themessage.focus()
  			}
  		         if (okSoFar==true)  submit();
		      }
	}
                  // --></script>
                  <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()">
                  <small><small>      You must fill in the fields marked with a <font color="red">*</font></small></small>
                  </td>
</tr>
         </table>
      </center></div>
</form>

 

 

mailer.php

<?php 
if(isset($_POST['submit']))
{ 
echo 'hello world';
// database information 
   $host = 'localhost';       
   $user = 'testdb'; 
   $password = 'password'; 
   $dbName = 'testdb';

// connect and select the database 
   	   $conn = mysql_connect($host, $user, $password) or die(mysql_error()); 
                $db = mysql_select_db($dbName, $conn) or die(mysql_error());

// Information for EMAIL
   $to = "admin@mydomain.net"; 
   $subject = $_POST['EmailSubject']; 
   $name_field = $_POST['SenderName']; 
                $email_field = $_POST['SenderEmail']; 
   $message = $_POST['ContactMessage']; 
   $ip = $_SERVER['REMOTE_ADDR'];
   $datetime = date('l dS \of F Y h:i:s A');
  
   $body = 'From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message'; 

   // insert new entry into database 
               $sql = 'insert into Contact (Contact_Name, Contact_Email, Contact_Date, Contact_IP, Contact_Subject, Contact_Message)
                         values ('$name_field', '$email_field', '$datetime', '$ip', '$subject', '$message')'; 
               $result = mysql_query($sql, $conn) or die(mysql_error());  

   echo 'Data has been submitted to site Administrator!'; 
   mail($to, $subject, $body);             
   	  
} 
else
{ 
   echo "Please try again!"; 
} 
?>

 

 

The DB connect is so that i can save a copy of the contact info in a db.  If this is messign it up, I will take it out.  I thank you for your help.  Is there a mor efficient way to do this than I am doing?

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/#findComment-262939
Share on other sites

Since there is no form input named submit, checking to see if $submit is set in the $_POST array will always fail.

 

I suppose you can always add a hidden input named submit with some non-null value (it will exist, therefore, and your present js submit can be used).

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/#findComment-262945
Share on other sites

First question: after you changed the submit type did you see the 'hello world' echoed? If not, the code is still failing the isset test.  If it passed that test, did anything get added to the database? There are many reasons why you might not have received the email, but let's make sure the code is executing before we look into those.

Link to comment
https://forums.phpfreaks.com/topic/52564-contactphp/#findComment-262978
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.