Can someone assist me with a php mail script?

Hi, the following html code I am struggling to get a functioning mail script for.

	<!-- Contact -->
		<section id="contact" class="wrapper">
			<div class="inner split">
			  <section>
			    <h2>Contact Us</h2>
			    <p>Feel free to contact us in order to arrange a free no obligation quote</p>
			    <form action="#" class="alt" method="POST">
						<div class="row uniform">
							<div class="6u 12u$(xsmall)">
								<input name="name" placeholder="Name" type="text">
							</div>
							<div class="6u$ 12u$(xsmall)">
								<input name="email" placeholder="Email" type="email">
							</div>
							<div class="12u$">
								<textarea name="message" placeholder="Message" rows="4"></textarea>
							</div>
						</div>
						<ul class="actions">
							<li><input class="alt" value="Send message" type="submit"></li>
						</ul>
					</form>
				</section>

That isn’t a mail script, that is a form.

Edit action="#" to
[php][/php]
or
[php][/php]

In file postToPage.php
[php]<?php

// Get the posted info.
$enteredName = $_POST[“name”];
$enteredEmail = $_POST[“email”];
$enteredMsg = $_POST[“message”];

// Display the info.
print “Name = “.$enteredName.”
”;
print “Email = “.$enteredEmail.”
”;
print “Message =

“.$enteredMsg.”

”;

// or email the info to …
$to = ‘[email protected]’;
$subject = “The subject”;
$message = “Name = “.$enteredName.”\n”;
$message = $message.“Email = “.$enteredEmail.”\n”;
$message = $message.“Message = \n”.$enteredMsg."\n";
mail($to, $subject, $message);

?>[/php]

Edit action="#" to

There is nothing wrong with submitting to the same page. It is actually a best practice to do so (Single page). The action attribute should just be left out completely.

I was trying to make the code simple by splitting the page with the form from the page that processes the sent data.
If posting to same page the you will need to check if data has been posted.
If not posted then display form,
else display, email or save the posted values.

[php]<?php
if($_POST[“email”]==""){
// Display form.
// <FORM ACTION="#" …
// …

} else {
// Save posted values to a file, email then and/or display them.
// Save to file.
$filePathName = “/serverSpaceRoot/home/records/DataFromForm.csv”;
$handle = fopen($filePathName, “a”);
$data[0] = date(“Y-m-d, H:i:s T”);
$data[1] = $_POST[“name”];
$data[2] = $_POST[“email”];
$data[3] = $_POST[“message”];
$data[4] = $_SERVER[“REMOTE_ADDR”];

fputcsv($handle, $data);
fclose($handle);

}
?>[/php]

Mark, that is actually backwards for a single page processor.

[php]if ( $_SERVER[‘REQUEST_METHOD’] == ‘POST’ ) {
// Validate and Process
}

// Display the form[/php]

Though personally, I would be calling services with the data rather than having the code all combined.

Sponsor our Newsletter | Privacy Policy | Terms of Service