Jump to content

some slight problems in the contactform - contact.php


peerlaan

Recommended Posts

A question about my contact.php:

Every time I open my website (in php) and open the tab "contact" I receive -

just once but of course every time I do this - an empty message as if someone

has sent me a message. It looks as if something generates an empty message as

soon as the tab "contact" is opened without a real message.

Of course every real sent message is received normally.

How can I delete this "automated" empty message just by opening the tab

"contact" on my website.

Hereunder the php-information, maybe someone sees an error, but everything

looks fine to me anyway.

<form action="<?php echo $PHP_SELF?>" method="post" name="contact formular">
<table width="100%" border="0">
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Name:
</font></td>
<td><input name="name" type="text" size="40" checked> <img src="images/star.gif"
alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970"
size="-1">E-mail address:
</font></td>
<td><input name="email" type="text" size="40" checked> <img
src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970"
size="-1">Subject:
</font></td>
<td><input name="subject" type="text" size="40" checked> <img
src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Your
message</font></td>
<td><textarea name="message" cols="50" rows="5"></textarea> <img
src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial">
<input type="reset" name="Reset" value="Reset">
</font></td>
<td><font face="Arial">
<input type="submit" name="Send" value="Send">
<p><img src="images/star.gif" alt="required field" align="absmiddle"> <font
face="Arial" color="#191970" size="-1">= Required </font></p>
</font></td>
</tr>
</table>
</form>
<?php
$recipient ="webmaster@peter-van-der-laan.nl";
$subject ="a reaction through the internet";
$header ="From:" . $email . "\n";
$mail_body = "The contact formular has been sent on " . date("d-m-Y") . "at" .
date("H:i") . " and executed.\n";
$mail_body .= "The next details have been filled in:\n\n";
$mail_body .= "Name: " . $_POST['name'] . "\n";
$mail_body .= "E-mail address: " . $_POST['email'] . "\n\n";
$mail_body .= "Message: " . $_POST['message'] . "\n";
$mail_body .= "\n\n -- End of the automatically generated message --";
mail ($recipient, $subject, $header, $mail_body);
require("footer.php");
?>

 

Another question, in this contact.php I want to create a small checkbox before

the command SENT with "email a copy of your message to your address" (meaning

that sender receives a copy of his message he wrote to me).

Are there any specific php commands for this? I cannot find any php scripts or

commands for this, only java-based commands, something like:

<div class="contact_email_checkbox">
<input name="email_copy" id="contact_email_copy" value="1" type="checkbox">
<label for="contact_email_copy" class="copy">E-mail a copy of this message to your own address.</label>
</div>

This works in php, but does not send a copy of the message made by the sender to sender's address.

 

Many thanks for the advices.

 

(edited by kenrbnsn to add


tags)

Link to comment
Share on other sites

<?php
if (isset($_POST['Send'])) {
//
// rest of the php code here
//
}
?>

 

Hi Ken, thanks, but inserting this gives a big problem, my contact.php is not visible and only shows a problem

Parse error: syntax error, unexpected $end in /storage/mijndomein/users/011504/public/sites/www.peter-van-der-laan.nl/contact.php on line 65

Any other solutions?

Link to comment
Share on other sites

Sorry but what do you mean by these codes, can you be clear please and give the exact syntax?

and where to put it exactly, on top of what?

Oh yeah, does this syntax mean as well that the sender of the message will also receive a copy of same on his address, I made this for the sender:

 

<tr>

<td class="style66" colspan="2"><input type="checkbox" name="copy" value="true" /><align="left" valign="top"><font face="Arial" color="#191970" size="-1">Send a copy to yourself</font></td>

</tr>

 

This is at least shown okay but if it works....

 

Thanks, Peter

Link to comment
Share on other sites

This how your code should look:

<form action="<?php echo $PHP_SELF?>" method="post" name="contact formular">
<table width="100%" border="0">
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Name:
</font></td>
<td><input name="name" type="text" size="40" checked> <img src="images/star.gif"
alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970"
size="-1">E-mail address:
</font></td>
<td><input name="email" type="text" size="40" checked> <img
src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970"
size="-1">Subject:
</font></td>
<td><input name="subject" type="text" size="40" checked> <img
src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Your
message</font></td>
<td><textarea name="message" cols="50" rows="5"></textarea> <img
src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Arial">
<input type="reset" name="Reset" value="Reset">
</font></td>
<td><font face="Arial">
<input type="submit" name="Send" value="Send">
<p><img src="images/star.gif" alt="required field" align="absmiddle"> <font
face="Arial" color="#191970" size="-1">= Required </font></p>
</font></td>
</tr>
</table>
</form>
<?php
  if (isset($_POST['Send'])) {
      $recipient = "webmaster@peter-van-der-laan.nl";
      $subject = "a reaction through the internet";
      $header = "From:" . $email . "\n";
      $mail_body = "The contact formular has been sent on " . date("d-m-Y") . "at" . date("H:i") . " and executed.\n";
      $mail_body .= "The next details have been filled in:\n\n";
      $mail_body .= "Name: " . $_POST['name'] . "\n";
      $mail_body .= "E-mail address: " . $_POST['email'] . "\n\n";
      $mail_body .= "Message: " . $_POST['message'] . "\n";
      $mail_body .= "\n\n -- End of the automatically generated message --";
      mail($recipient, $subject, $header, $mail_body);
      require("footer.php");
  }
?>

 

Ken

Link to comment
Share on other sites

Thanks Ken, I don't receive any automated empty message any longer now, only the normal messages issued by sender.

But still wondering about one thing: under <td>textarea name="message" etc etc</tr> I told you I inserted

<tr>

<td class="style66" colspan="2"><input type="checkbox" name="copy" value="true" /><align="left" valign="top"><font face="Arial" color="#191970" size="-1">Send a copy to yourself</font></td></tr>, of course before the Reset and Send commands.

I can see this checkbox and of course the possible to insert "x" but unfortunately sender does NOT receive a copy of his message.

What could be wrong?

Thanks, Peter

 

Link to comment
Share on other sites

You have to change the script to look to see if the check box is set and add the appropriate headers if it is:

<?php
$header = "From:" . $email . "\n";
if (isset($_POST['copy']) && $_POST['copy'] == 'true') {
    $header .= 'CC: ' . $email ."\n";
?>

 

Ken

Link to comment
Share on other sites

I did this Ken, by I got a syntax error: Parse error: syntax error, unexpected $end in /storage/mijndomein/users/011504/public/sites/www.peter-van-der-laan.nl/contact.php on line 69

Can you pls repeat exactly where I have to insert this from (I did this):

<?php

  if (isset($_POST['Send'])) {

      $recipient = "webmaster@peter-van-der-laan.nl";

      $subject = "a reaction through the internet";

      $header = "From:" . $email . "\n";

if (isset($_POST['copy']) && $_POST['copy'] == 'true') {

      $header .= 'CC: ' . $email ."\n";

      $mail_body = "The contact formular has been sent on " . date("d-m-Y") . "at" . date("H:i") . " and executed.\n";

      $mail_body .= "The next details have been filled in:\n\n";

      $mail_body .= "Name: " . $_POST['name'] . "\n";

      $mail_body .= "E-mail address: " . $_POST['email'] . "\n\n";

      $mail_body .= "Message: " . $_POST['message'] . "\n";

      $mail_body .= "\n\n -- End of the automatically generated message --";

      mail($recipient, $subject, $header, $mail_body);

      require("footer.php");

  }

?>

 

Thanks dear Ken.

Link to comment
Share on other sites

No strange views anymore but now when I make a test message with a different email address and insert x for copy to sender, I don't receive any message and sender does not receive any message.

I repeat what is in my php file:

<?php

if (isset($_POST['Send'])) {

      $recipient = "webmaster@peter-van-der-laan.nl";

      $subject = "a reaction through the internet";

      $header = "From:" . $email . "\n";

if (isset($_POST['copy']) && $_POST['copy'] == 'true') {

}

      $header .= 'CC: ' . $email ."\n";

      $mail_body = "The contact formular has been sent on " . date("d-m-Y") . "at" . date("H:i") . " and executed.\n";

      $mail_body .= "The next details have been filled in:\n\n";

      $mail_body .= "Name: " . $_POST['name'] . "\n";

      $mail_body .= "E-mail address: " . $_POST['email'] . "\n\n";

      $mail_body .= "Message: " . $_POST['message'] . "\n";

      $mail_body .= "\n\n -- End of the automatically generated message --";

      mail($recipient, $subject, $header, $mail_body, $header);

      require("footer.php");

  }

?>

Why don't I and sender receive a message/copy? Pls note if I don't close the new if command separately I'll have the syntax error. You may see twice closing now.

Thanks

Link to comment
Share on other sites

You mis-typed what I had given you. Change

<?php
if (isset($_POST['copy']) && $_POST['copy'] == 'true') {
}
      $header .= 'CC: ' . $email ."\n";
?>

to

<?php
if (isset($_POST['copy']) && $_POST['copy'] == 'true') {
      $header .= 'CC: ' . $email ."\n";
}
?>

 

If that doesn't work, please post all your code again.

 

Ken

Link to comment
Share on other sites

This is my whole file, I nor sender receives a message, still. Look under please. Of course you can read the entire file, but I don't think that is important, but OK, pls advise the failure of correct sending/copying.

<?php
require("header.php");
?>
<br>

<div class="wDiv3" align="center">
<br><br>
You can leave messages or commands or fanmail about Peter and
his music on the weblog, welcome!
<br><br>
If you want to contact Peter, please contact the webmaster. See the contact formular hereunder.
<br>
Peter however says: "I'll try to reply your message anyway, if not, don't be disappointed,
<br>
because I'm glad that you contact me and are interested. Thanks anyway."
<br><br>
<p>Please do not send any advertising material or spam. The webmaster.</p>
<br><br>
<form action="<?php echo $PHP_SELF?>" method="post" name="contact_form">
<table width="100%" border="0">
<tr> 
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Name: </font></td>
<td><input name="name" type="text" size="40" checked> <img src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr> 
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">E-mail address: 
</font></td>
<td><input name="email" type="text" size="40" checked> <img src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr> 
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Subject: 
</font></td>
<td><input name="subject" type="text" size="40" checked> <img src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr> 
<td align="left" valign="top"><font face="Arial" color="#191970" size="-1">Your message</font></td>
<td><textarea name="message" cols="60" rows="10"></textarea> <img src="images/star.gif" alt="required field" align="absmiddle"></td>
</tr>
<tr>
<td class="style66" colspan="2"><input type="checkbox" name="copy" value="true" /><align="left" valign="top"><font face="Arial" color="#191970" size="-1">Send a copy to yourself</font></td>
</tr>
<tr> 
<td align="left" valign="top"><font face="Arial"> 
<input type="reset" name="Reset" value="Reset">
</font></td>
<td><font face="Arial">
<input type="submit" name="Send" value="Send">
<p><img src="images/star.gif" alt="required field" align="absmiddle"> <font face="Arial" color="#191970" size="-1">= Required </font></p>
</font></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['Send'])) {
      $recipient = "webmaster@peter-van-der-laan.nl";
      $subject = "a reaction through the internet";
      $header = "From:" . $email . "\n";
if (isset($_POST['copy']) && $_POST['copy'] == 'true') {
      $header .= 'CC: ' . $email ."\n";
}
      $mail_body = "The contact formular has been sent on " . date("d-m-Y") . "at" . date("H:i") . " and executed.\n";
      $mail_body .= "The next details have been filled in:\n\n";
      $mail_body .= "Name: " . $_POST['name'] . "\n";
      $mail_body .= "E-mail address: " . $_POST['email'] . "\n\n";
      $mail_body .= "Message: " . $_POST['message'] . "\n";
      $mail_body .= "\n\n -- End of the automatically generated message --";
      mail($recipient, $subject, $header, $header, $mail_body);
      require("footer.php");
  }
?>

 

Hope to hear the final solution now, so that I can receive messages and that sender can receives their copies of messages.

Thanks Ken.

Link to comment
Share on other sites

Dear Ken, pls read my entire file.

Now I'm receiving the messages sent to me, but still sender does not receive a copy.

What oh what's the failure?

Yeah, I know PHP, but only the contact things are rather difficult, and what they advice on the internet sometimes is not correct, as I tried it.

Anyway, your advices work finally, so I hope you can also solve this last problem for the contacts, so that sender actually receives a copy, but pls read me file before.

Thanks.

Link to comment
Share on other sites

The following php code works. I tested it. If it doesn't work for you, then something is not set up correctly on your server:

<?php
if (isset($_POST['Send'])) {
      $recipient = "webmaster@peter-van-der-laan.nl";
      $subject = "a reaction through the internet";
      $header = "From:" . stripslashes($_POST['name']) . ' <' . $_POST['email'] . ">\n";
  if (isset($_POST['copy']) && $_POST['copy'] == 'true') {
		$header .= 'BCC: ' . $_POST['email'] ."\n";
  }
	$header .= "\n";
      $mail_body = "The contact formular has been sent on " . date("d-m-Y \a\\t H:i") .  " and executed.\n";
      $mail_body .= "The next details have been filled in:\n\n";
      $mail_body .= "Name: " . stripslashes($_POST['name']) . "\n";
      $mail_body .= "E-mail address: " . $_POST['email'] . "\n\n";
      $mail_body .= "Message: \n" . stripslashes($_POST['message']) . "\n";
      $mail_body .= "\n\n -- End of the automatically generated message --";
      mail($recipient, $subject, $mail_body, $header, '-f ' . $_POST['email']);
      require("footer.php");
}
?>

 

Ken

Link to comment
Share on other sites

Hi dear Ken,

 

It's finally working perfectly now. I receive the sent messages, the sender receives his copies, so thanks to you the problem has been solved. Great!

 

A final question, if you read my file, if someone is making mistakes, e.g. wrong e-mail address, no name whatever, does he/she see that the message is NOT sent then, I think - but pls correct me - this should be some "echo", if so: how and where in my php file should I insert this? Or has this already been included in my file?

 

This will definitely be the last question for my php file, as all other php files are OK and are perfect, also the swf file I inserted as well as other files.

Another site I made was made in/with Joomla, you probably know this, also something great anyway.

 

Thanks for your last advice.

Peter

Link to comment
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.