Jump to content

Contact Form problem


gastroll

Recommended Posts

Hez guys,

 

first of all I have to admit that I have NO clue about php and

building an contact form is my first contact with it.

 

However I use the following contact form:

 

<form id="formID" class="formular" action="restaurant-kontakt-sent.php" method="post" >

<fieldset>
<legend>
Persönliche Angaben
</legend>
 <table>
	<tr>
	<td>
	<span style="color:#FF0000">*</span><span>Name:</span>
	</td>
	<td>
	<label>
<input value="<?=$_SESSION['post']['name']?>" class="validate[required,custom[onlyLetterSp]] text-input" type="text" name="name" id="name" />
	</label>
		</td>
		</tr>
		<tr>
		<td>
		 <span style="color:#FF0000">*</span><span>Email: </span>
		</td> 
		 <td>
		<label>
<input value="<?=$_SESSION['post']['email']?>" class="validate[required,custom[email]] text-input" type="text" name="email" id="email" />
	</label>
	</td>
						</tr>
						<tr>
						<td>
						<span>Adresse:</span>
						</td> 
		                <td>
<label>
<input value="<?=$_SESSION['post']['adresse']?>" class="validate[custom[onlyLetterNumber]] text-input" type="text" name="adresse" id="adresse" />
</label>
</td>
						</tr>
						<tr>
						<td>
 <span>Telefon: </span><br><span style="font-size:9px;">(Bitte mit Vorwahl)</span>
		                </td> 
		                <td>
		                 <label>
<input value="<?=$_SESSION['post']['tele']?>" class="validate[custom[phone]] text-input" type="text" name="tele" id="tele" />
		                </label>
		                </td>
						</tr>
		                </table>
		            </fieldset> 
		             
		            <fieldset>
		                <legend>
		                    Weitere Angaben
		                </legend>
		                 <table>
						<tr>
						<td>
		                <span>Unternehmen:</span>
		                </td>
						<td>
		                <label>
<input value="<?=$_SESSION['post']['uname']?>" class="validate[custom[onlyLetterNumber]] text-input" type="text" name="uname" id="uname" />
		                </label>
		                </td>
						</tr>
						<tr>
						<td>
		                <span>Website:</span>
		               </td>
						<td>
		                 <label>
 <input value="http://" class="validate[custom[url]] text-input" type="text" name="website" id="website" />
		                </label>
		                 </td>
						</tr>
						<tr>
						<td>
		                <span>Unternehmen <br>zuordnen:</span>
		                </td>
		                <td>
		                <label>
<select name="unternehmenstyp" id="unternehmenstyp" class="validate[custom]">
		                        <option value="option1">Bars, Pubs & Kneipen</option>
		                        <option value="option2">Cafes & Bistros</option>
		                        <option value="option3">Catering & Partyservice</option>
		                        <option value="option1">Clubs & Diskotheken</option>
		                        <option value="option2">Events & Veranstaltungen</option>
		                        <option value="option3">Imbiss, Pizza & Fast Food</option>
		                        <option value="option1">Kinos</option>
		                        <option value="option2">Lieferservice</option>
		                        <option value="option3">Pensionen, Hostels & Jugendherbergen</option>
		                        <option value="option3">Restaurants</option>
		                        <option value="option3">Andere</option>
		                    </select>
		                  </td>
						</tr>
						</table>  
		                </label>
		                
		       	 </fieldset>
				 <fieldset>
		                <legend>
		                 Ihre Nachricht
		                </legend>
		                 <table>
						<tr>
						<td>
						<span>Betreff:</span>
						</td>
						<td>
		                <label>
<input value="<?=$_SESSION['post']['betreff']?>" class="validate[custom[onlyLetterNumber]] text-input" type="text" name="betreff" id="betreff" />
		                </label>
		                </td>
		                </tr>
		                <tr>
		                <td>
		                <span>Nachricht:</span>
		                </td>
		                <td>
		                <label>
<textarea class="validate[required] text-input" rows="4" cols="40" name="anschreiben" id="anschreiben" > <?=$_SESSION['post']['message']?> </textarea>
		                </label>
		                </td>
		                </tr>
		                </table>

		                 <!--
		                 <div>
                            <span>Datei zum Anhang hinzufügen:</span>
<input class="validate[custom[]] text-input" type="file" name="anhang" id="anhang"/>
		                </div>
		                -->
		            </fieldset>

<input class="submit" type="submit" value="Senden!"/><hr/>
	        </form>

 

And the following restaurant-kontakt-sent.php:

 

<?php
if(isset($_POST['submit']))
{
$to = 'info@mydomain.de';
$name = $_POST['name'] ; 
$email = $_POST['email'] ; 
$adresse = $_POST['adresse'] ; 
$telefon = $_POST['tele'] ; 
$unternehmensname = $_POST['uname'] ; 
$unternehmenstyp = $_POST['unternehmenstyp'] ; 
$betreff = $_POST['betreff'] ;
$anschreiben = $_POST['anschreiben'] ; 
//$headers = "From: $Nachname <$Email>"; 

//$error = "";
//if (trim($nachname)=="" || trim($email)==""|| trim($anschreiben)=="" )
//{
//$error = "Ooops! Nachname, Emailadresse und Anschreiben sind Pflichtfelder." 
//}

mail($to, $vorname, $nachname, $email, $adresse, $telefon, $unternehmensname, $unternehmenstyp, $betreff, $anschreiben) ;

if (mail($to, $vorname, $nachname, $email, $adresse, $telefon, $unternehmensname, $unternehmenstyp, $betreff, $anschreiben))
header("Location:/restaurant-kontakt-gesendet.html");

else 
header("Location:/restaurant-kontakt-error.html");
}  
?> 

 

My problem is:

1. There is no mail coming (my host is 1und1.de and it is not inside the span or junk folder)?

2. And after pushing the submit button the user gets not passed to the the  restaurant-kontakt-error.html or restaurant-kontakt-gesendet.html.

 

Could anyone give me the right direction?

Link to comment
Share on other sites

I believe you are confusing how the mail() function works.

 

The mail functions requires certain inputs to send.

 

Such as:

 

email address to deliver to

email address delivered from

the subject

the message

email headers

 

 

 


<?php
if(isset($_POST['submit']))
{
$to = 'info@mydomain.de';
$subject = "New Message";  
$name = $_POST['name'] ; 
$email = $_POST['email'] ; 
$adresse = $_POST['adresse'] ; 
$telefon = $_POST['tele'] ; 
$unternehmensname = $_POST['uname'] ; 
$unternehmenstyp = $_POST['unternehmenstyp'] ; 
$betreff = $_POST['betreff'] ;
$anschreiben = $_POST['anschreiben'] ; 
$headers = "From: $from";

$message = "

See information from form below,\n\n

Name: $name\n
Email: $email\n
Adresse: $adresse\n
Telefon: $telefon\n
Unternehmensname: $unternehmensname\n
Unternehmenstyp: $unternehmenstyp\n
Betreff: $betreff\n
Anschreiben: $anschreiben\n\n\n";

// Send the message    
$sendit = @mail($to, $subject, $message, $headers);   

if($sendit){

header("Location: /restaurant-kontakt-gesendet.html");

}else{

header("Location: /restaurant-kontakt-error.html");

}

}  
?> 

 

 

 

Link to comment
Share on other sites

Hey Twistedweb123,

thanks for your post:

I put your changes in my file.

Here is my new file:

 

<?php
if(isset($_POST['submit']))
{

$to = 'info@gastrollogy.de';
$subject = $_POST['betreff'] ;  
$name = $_POST['name'] ; 
$email = $_POST['email'] ; 
$adresse = $_POST['adresse'] ; 
$telefon = $_POST['tele'] ; 
$unternehmensname = $_POST['uname'] ; 
$website = $_POST['website'] ; 
$unternehmenstyp = $_POST['unternehmenstyp'] ; 
$anschreiben = $_POST['anschreiben'] ; 
$headers = "From: $email";

  $message = "

See information from form below,\n\n

Betreff: $betreff\n
Name: $name\n
Email: $email\n
Adresse: $adresse\n
Telefon: $telefon\n
Unternehmensname: $unternehmensname\n
Website: $website\n
Unternehmenstyp: $unternehmenstyp\n
Anschreiben: $anschreiben\n\n\n";

// Send the message    
$sendit = @mail($to, $subject, $message, $headers);   

if($sendit){

header("Location: /restaurant-kontakt-gesendet.html");

}else{

header("Location: /restaurant-kontakt-error.html");

}

}  
?>

 

 

But:

(tested different email addresses)

- did not received a email (no spam)

- and after submitting the user is not redirected to the thank-you.html

 

Any further idea?

Link to comment
Share on other sites

Basic test to find out if your email mail() is working.

NOTE: this will have NO headers and most likely end up in your Junk email box. Will also be from your server not u.

Try it and we can go from there.

$strTo = 'YOUR@EMAIL.com';
$strSubject = 'My Test Email';
$strBody = 'This is the Email message';
if(mail($strTo, $strSubject, $strBody){
echo 'Mail has been sent';
}else{
echo 'This is going to cause a headache';
}

Link to comment
Share on other sites

  • 4 weeks later...

Hi, sorry that I respond so late (have been in holiday for a while).

So put your test version in my file and it did not work out.

 

here is my new php file.

<?php

$strTo = 'xxx@googlemail.com';

$strSubject = 'My Test Email';

$strBody = 'This is the Email message';

if(mail($strTo, $strSubject, $strBody){

echo 'Mail has been sent';

}else{

echo 'This is going to cause a headache';

}

?>

 

after submit

the browser tells me:

 

Parse error: syntax error, unexpected '{' in /homepages/xx/xxx/htdocs/xxx.de/kontakt-sent.php on line 5

 

Link to comment
Share on other sites

You're missing a closing ")" on this line:

<?php
if(mail($strTo, $strSubject, $strBody){
?>

it should be

<?php
if(mail($strTo, $strSubject, $strBody)){
?>

 

BTW, when posting code, please put the code between


tags.

 

Ken

Link to comment
Share on other sites

Ups, sorry next time I will use the right code highlight thing.

 

Fiiinaly I got a email in my account: the test mail worked.

 

So can anyone see what I am doing wrong on my original kontakt-sent.php? :

 

<?php
if(isset($_POST['submit']))
{

$to = 'my@website.de';
$subject = $_POST['betreff'] ;  
$name = $_POST['name'] ; 
$email = $_POST['email'] ; 
$adresse = $_POST['adresse'] ; 
$telefon = $_POST['tele'] ; 
$unternehmensname = $_POST['uname'] ; 
$website = $_POST['website'] ; 
$unternehmenstyp = $_POST['unternehmenstyp'] ; 
$anschreiben = $_POST['anschreiben'] ; 
$headers = "From: $email";

  $message = "

See information from form below,\n\n

Betreff: $betreff\n
Name: $name\n
Email: $email\n
Adresse: $adresse\n
Telefon: $telefon\n
Unternehmensname: $unternehmensname\n
Website: $website\n
Unternehmenstyp: $unternehmenstyp\n
Anschreiben: $anschreiben\n\n\n";

// Send the message    
$sendit = @mail($to, $subject, $message, $headers);   

if($sendit){

header("Location: http://www.mywebsite.de/kontakt-gesendet.html");

}else{

header("Location: http://www.mywebsite.de/kontakt-error.html");

}

}  
?>

 

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.