Jump to content

connect email contact form with php

Fredrikmikael

hello i have a contact form and a php script to send email, i have tried it with the original contact form that came with it and it works perfectly, but i want to use my own contact form that looks a whole lot better, but how do i go about connecting them ?

contactform.png

 

This is the contact form showed in html. it is not it's own html document it is inside the core of the website

	<div class = "modal fade" id = "contact" role = "dialog">					<div class = "modal-dialog">						<div class = "modal-content">							<form class = "form-horizontal">								<div class = "modal-header">									<h4>Kontakt Sjøveganlan</h4>								</div>								<div class = "modal-body">																<div class = "form-group">																				<label for = "contact-name" class = "col-lg-2 control-label">Name:</label>										<div class = "col-lg-10">																					<input type = "text" class = "form-control" id = "contact-name" placeholder = "Full Name">																				</div>																			</div>																		<div class = "form-group">																				<label for = "contact-email" class = "col-lg-2 control-label">Email:</label>										<div class = "col-lg-10">																					<input type = "email" class = "form-control" id = "contact-email" placeholder = "you@[member='Example'].com">																				</div>																			</div>											<div class = "form-group">																				<label for = "contact-msg" class = "col-lg-2 control-label">Message:</label>										<div class = "col-lg-10">																					<textarea class = "form-control rows = "20"></textarea>																				</div>																			</div>															</div>								<div class = "modal-footer">									<a class = "btn btn-default" data-dismiss = "modal">close</a>									<button class = "btn btn-primary" type = "submit">Send</button>								</div>							</form>						</div>					</div>				</div>

This is the PHP "send_form_email.php"

<?php if(isset($_POST['email'])) {           // EDIT THE 2 LINES BELOW AS REQUIRED     $email_to = "linus_is_hot@yahoo.com";     $email_subject = "Kontakt oss - #sjøveganlan";                 function died($error) {         // your error code can go here         echo "We are very sorry, but there were error(s) found with the form you submitted. ";         echo "These errors appear below.<br /><br />";         echo $error."<br /><br />";         echo "Please go back and fix these errors.<br /><br />";         die();     }           // validation expected data exists     if(!isset($_POST['first_name']) ||         !isset($_POST['last_name']) ||         !isset($_POST['email']) ||         !isset($_POST['telephone']) ||         !isset($_POST['comments'])) {         died('We are sorry, but there appears to be a problem with the form you submitted.');           }           $first_name = $_POST['first_name']; // required     $last_name = $_POST['last_name']; // required     $email_from = $_POST['email']; // required     $telephone = $_POST['telephone']; // not required     $comments = $_POST['comments']; // required           $error_message = "";     $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';   if(!preg_match($email_exp,$email_from)) {     $error_message .= 'The Email Address you entered does not appear to be valid.<br />';   }     $string_exp = "/^[A-Za-z .'-]+$/";   if(!preg_match($string_exp,$first_name)) {     $error_message .= 'The First Name you entered does not appear to be valid.<br />';   }   if(!preg_match($string_exp,$last_name)) {     $error_message .= 'The Last Name you entered does not appear to be valid.<br />';   }   if(strlen($comments) < 2) {     $error_message .= 'The Comments you entered do not appear to be valid.<br />';   }   if(strlen($error_message) > 0) {     died($error_message);   }     $email_message = "Form details below.\n\n";           function clean_string($string) {       $bad = array("content-type","bcc:","to:","cc:","href");       return str_replace($bad,"",$string);     }	          $email_message .= "First Name: ".clean_string($first_name)."\n";     $email_message .= "Last Name: ".clean_string($last_name)."\n";     $email_message .= "Email: ".clean_string($email_from)."\n";     $email_message .= "Telephone: ".clean_string($telephone)."\n";     $email_message .= "Comments: ".clean_string($comments)."\n";             // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @[member='mail']($email_to, $email_subject, $email_message, $headers);  ?>   <!-- include your own success html here -->   Thank you for contacting us. We will be in touch with you very soon.   <?php } ?>

How do i connect these two ?

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Change this line:

<form class = "form-horizontal">

 

To:

<form class = "form-horizontal" action="send_form_email.php">

 

Making sure the html and php files are in the same directory. The PHP file will need some modifications, as the html form has nowhere near the inputs required by the php file. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Change this line:

<form class = "form-horizontal">

To:

<form class = "form-horizontal" action="send_form_email.php">

Making sure the html and php files are in the same directory. The PHP file will need some modifications, as the html form has nowhere near the inputs required by the php file. 

 

ok, i have modifyed it, but it doesn't work. what is wrong now ?

 

<?php if(isset($_POST['email'])) {           // EDIT THE 2 LINES BELOW AS REQUIRED     $email_to = "Secrets, shhhh";     $email_subject = "Kontakt oss - #sjøveganlan";                 function died($error) {         // your error code can go here         echo "We are very sorry, but there were error(s) found with the form you submitted. ";         echo "These errors appear below.<br /><br />";         echo $error."<br /><br />";         echo "Please go back and fix these errors.<br /><br />";         die();     }           // validation expected data exists     if(!isset($_POST['contact-name']) || // Navn 		!isset($_POST['contact-email']) || //epost         !isset($_POST['contact-msg'])) { // melding 		died('Det ser ut som att det er en feil med formen du sendte.');     }           $first_name = $_POST['contact-name']; // required  //   $last_name = $_POST['last_name']; // required     $email_from = $_POST['contact-email']; // required  //   $telephone = $_POST['telephone']; // not required     $comments = $_POST['contact-msg']; // required           $error_message = "";     $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';   if(!preg_match($email_exp,$email_from)) {     $error_message .= 'Epost adressen din er ut til og være feil<br />';   }     $string_exp = "/^[A-Za-z .'-]+$/";   if(!preg_match($string_exp,$first_name)) {     $error_message .= 'Det ser ut som att navnet ditt er "feil".<br />';   }   if(!preg_match($string_exp,$last_name)) {     $error_message .= 'The Last Name you entered does not appear to be valid.<br />';   }   if(strlen($comments) < 2) {     $error_message .= 'Venligst skriv en melding<br />';   }   if(strlen($error_message) > 0) {     died($error_message);   }     $email_message = "Form details below.\n\n";           function clean_string($string) {       $bad = array("content-type","bcc:","to:","cc:","href");       return str_replace($bad,"",$string);     }	          $email_message .= "First Name: ".clean_string($first_name)."\n";    // $email_message .= "Last Name: ".clean_string($last_name)."\n";     $email_message .= "Email: ".clean_string($email_from)."\n";   //  $email_message .= "Telephone: ".clean_string($telephone)."\n";     $email_message .= "Comments: ".clean_string($comments)."\n";             // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @[member=mail]($email_to, $email_subject, $email_message, $headers);  ?>   <!-- include your own success html here -->   Thank you for contacting us. We will be in touch with you very soon.   <?php } ?>

and i have changed the <form> line i html

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Oh, I forgot. The form tag requires method="post" too:

<form class="leave as is" action="linktophp.php" method="post">

Going to assume the PHP file was modified properly, and it looks to be the case. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Oh, I forgot. The form tag requires method="post" too:

<form class="leave as is" action="linktophp.php" method="post">

Going to assume the PHP file was modified properly, and it looks to be the case. 

There is still something wrong with the script

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Error messages? It'll help narrow things down. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Error messages? It'll help narrow things down. 

no, sorry. There isnt any error messages.

 

you can try yourself if you want

just press "Kontakt oss"

 

http://sjovegan-ikt.no/boots/index.htm

(it is just the index that has the "functioning" contact form.

you just get redirected to the php file.

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just to be sure, check the following line in the PHP:

@[member=mail]($email_to, $email_subject, $email_message, $headers); 

The @ shouldn't exist. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just to be sure, check the following line in the PHP:

@[member='mail']($email_to, $email_subject, $email_message, $headers); 

The @ shouldn't exist. 

 

doesnt seem to change anything

mail($email_to, $email_subject, $email_message, $headers); 

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Error messages? It'll help narrow things down. 

 

by the way, here is the original form  /  php, that i used

 

http://www.freecontactform.com/email_form.php

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Okie. Start from square one. 

Get rid of any HTML pertaining to the form and create the html form from scratch, without any unnecessary tags/styles. 

 

Also, if you don't have much experience creating forms (html and PHP), read up on it. It'll help knowing how to actually create the files from scratch. http://www.codecademy.com/tracks/php

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Okie. Start from square one. 

Get rid of any HTML pertaining to the form and create the html form from scratch, without any unnecessary tags/styles. 

 

Also, if you don't have much experience creating forms (html and PHP), read up on it. It'll help knowing how to actually create the files from scratch. http://www.codecademy.com/tracks/php

 

i am using the bootstrap framework, it cant have anything to do with that? by some small chance

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Okie. Start from square one. 

Get rid of any HTML pertaining to the form and create the html form from scratch, without any unnecessary tags/styles. 

 

Also, if you don't have much experience creating forms (html and PHP), read up on it. It'll help knowing how to actually create the files from scratch. http://www.codecademy.com/tracks/php

 but we have the basic form that is on this -> http://www.freecontactform.com/email_form.php <- site.

why dont use that instead of creating a new one ?

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Possibly. Random question though: where is this actually hosted? Shared server? It's possible the server doesn't have a mailserver configured, or has specific mail() function rules: http://stackoverflow.com/questions/5465729/how-do-you-send-e-mail-via-php-on-a-godaddy-shared-host-using-codeigniter

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

 but we have the basic form that is on this -> http://www.freecontactform.com/email_form.php <- site.

why dont use that instead of creating a new one ?

Sure, you can use that form too, since it works. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Possibly. Random question though: where is this actually hosted? Shared server? It's possible the server doesn't have a mailserver configured, or has specific mail() function rules: http://stackoverflow.com/questions/5465729/how-do-you-send-e-mail-via-php-on-a-godaddy-shared-host-using-codeigniter

 

no i tested it with the original form / php. and i recived the email with what i typed in the form.

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Sure, you can use that form too, since it works. 

 

i was wondering, does the "Method" have to be before "Action" or doesnt it matter?

<form class = "form-horizontal" action = "send_form_email.php" method = "post">

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

 

i was wondering, does the "Method" have to be before "Action" or doesnt it matter?

<form class = "form-horizontal" action = "send_form_email.php" method = "post">

It doesn't really matter. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

It doesn't really matter. 

 

still trying to figure it out, or have you given up ?

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I think I may have something similar to this somewhere on my computer, lemme see if I can find it and compare the code.

GW2: Vettexl.9726

Link to comment
Share on other sites

Link to post
Share on other sites

I think I may have something similar to this somewhere on my computer, lemme see if I can find it and compare the code.

Awesome, please get back to me :)

System

Spoiler

CPU: Intel Core i7 5820K @4.5GHz - 1.230v  RAM: HyperX Fury DDR4 4x4GB 2666MHz  MB: MSI X99S SLI PLUS  CASE: NZXT H440  CPU-COOLER: Fractal Design Kelvin S24  PSU: Corsair RM1000W w/ white sleeved cable kit  GPU: MSI GeForce RTX 2070 ARMOR  MONITOR: LG 27GL850-B  STORAGE: Samsung 970 EVO 1TB M.2, Samsung 840 EVO 256GB,  WD Red 3TB

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
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

×