Jump to content

Contact Form redirecting to php (problem)


Nic727

Recommended Posts

Hi,

 

When I fill my contact form with informations and click on the submit button, I'm redirected to the contact.php file. How can I avoid that?

 

My current code for my form is that :

<?php

if(isset($_POST['submit'])){
	
    $to = 'contact@nicolas-duclos.com';

	/***** Valeurs du formulaire *****/
	
    $name = $_POST['name']; //Required
    $lastname = $_POST['lastname'];

    $email = $_POST['email']; //Required
    $phone = $_POST['phone'];

    $object = $_POST['object']; //Required
    $message = $_POST['message']; //Required

    $headers = "From: " .$name. "\r\n";
    $headers .= "Reply-To: ".$email."\r\n";
	$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; 

	$message = " Name: " . $name . "\r\n Last Name: " . $lastname . "\r\n Email: " . $email . "\r\n Telephone: " . $phone . "\r\n Object: " . $object . "\r\n message: " . $message;

    mail($to, $object, $message, $headers);
	
}
 ?>

Also, there is some stuffs I don't understand when receiving emails.

Instead of having : FROM [Name, Last Name] with object [Object]

I have : FROM [Name@server12332.com] Object [Object]. Anyway to do this?

 

Finally, is there a way to seperate the message from all other informations in $message? Maybe a line or something else.

 

thank you.

 

 

Link to comment
Share on other sites

There's no redirection in that code, so I assume you just have your form submitting to contact.php.

 

Instead of having : FROM [Name, Last Name] with object [Object]

I have : FROM [Name@server12332.com] Object [Object]. Anyway to do this?

I'm not sure what you're asking.

 

Finally, is there a way to seperate the message from all other informations in $message? Maybe a line or something else.

You can use \r\n to add more line breaks.
Link to comment
Share on other sites

Hmm... Weird. What about my form?

<form method="post" action="contact.php">
				<p>Les champs sont obligatoires*</p>
				
			<div class="rowform">	
				<div class="half gauche">	
				    <label>Prénom*</label>
				    <input name="prenom" id="prenom" type="text">
				</div>
				 
				<div class="half droite">	
				    <label>Nom</label>
				    <input name="nom" id="nom" type="text">
				</div>
			</div>
				
			<div class="rowform">
				<div class="half gauche">
					<label>Courriel*</label>
					<input name="courriel" id="courriel" type="courriel">
				</div>	
			 
				<div class="half droite">	
					<label>Téléphone</label>
					<input name="phone" id="phone" type="text">
				</div>	
			</div>
		
			<div class="rowform">	
				<label>Sujet*</label>
				<input name="sujet" id="sujet" type="text">
			</div>
				
			<div class="rowform">	
				<label>Votre message*</label>
				<textarea name="message"></textarea>
			</div>
				<div class="end-form">	
                    <button id="submit" class="submit" name="submit" type="submit" value="envoyer"><i class="fa fa-paper-plane" aria-hidden="true"></i> Envoyer</button>
				</div>	
			</form>

For the other thing :

 

1464290101-000123.png

Link to comment
Share on other sites

The form submits to contact.php. If that's your PHP code, then after sending the email you can show some HTML or redirect to another page.

 

For the From header, the RFC for email contains several examples of formatting the address in that header. You can write the name then the email address in angle brackets:

 

https://tools.ietf.org/html/rfc2822#appendix-A.1

Link to comment
Share on other sites

The form submits to contact.php. If that's your PHP code, then after sending the email you can show some HTML or redirect to another page.

 

For the From header, the RFC for email contains several examples of formatting the address in that header. You can write the name then the email address in angle brackets:

 

https://tools.ietf.org/html/rfc2822#appendix-A.1

 

Thank you, but for my contact.php I just want to :

 

1. Stay on the same page and just clear the form

or

2. Remove form and show a message like "Thank you".

 

These thing I can find on the web, but how can I avoid redirecting to contact.php?

Edited by Nic727
Link to comment
Share on other sites

1. Stay on the same page and just clear the form

add this : header('location : your_form_page.php');

after the folowing :

 mail($to, $object, $message, $headers);
2. Remove form and show a message like "Thank you".

you can do that using sessions in php or using Ajax calls to send the form data to contact.php

 

http://www.w3schools.com/ajax/

http://www.w3schools.com/php/php_sessions.asp

 

Good luck

Link to comment
Share on other sites

1. Stay on the same page and just clear the form

add this : header('location : your_form_page.php');

after the folowing :

 mail($to, $object, $message, $headers);
2. Remove form and show a message like "Thank you".

you can do that using sessions in php or using Ajax calls to send the form data to contact.php

 

http://www.w3schools.com/ajax/

http://www.w3schools.com/php/php_sessions.asp

 

Good luck

 

 

I was thinking about using javascript or jQuery to verify form and make something with that.

 

Not sure it will work if I will do that :

header('location : index.html);

It will just reload the page from the top.

 

I will try to find something with JavaScripts to make the form clear or remove form to show a success message.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...