Quantcast
Channel: PHP Problems - CSS-Tricks Forums
Viewing all articles
Browse latest Browse all 47

Sending An email from a form Using PHP

$
0
0
Hi, I am now leaerning php and kinda getting the hang of the language but I am stuck... :S I am trying to send an email from a form using php and I keep getting the error undefined variable

here is my form code...
<form method="post" action="" onsubmit="return validation(this)">

First Name:<br/>
<input type="text" name="CustomerFname" size="30" />
<br/>
Surname:<br/>
<input type="text" name="CustomerLname" size="30" />
<br/>
Email:<br/>
<input type="text" name="CustomerMail" size="30" />
<br/>
Contact:<br/>
<input type="text" name="CustomerNumber" size="30" />
<br/>
Comments:<br/>
<textarea id="CustomerComments"></textarea>
<br/>
<input type="submit" name="submit" value="Send!"/>

</form>

my php script is....

<?php

if(array_key_exists('send',$_POST)) {

$to = 'kevon.garcia@gmail.com';
$subject = 'Customer Request';

$FirstName = $_POST['CustomerFname'];
$LastName = $_POST['CustomerLname'];
$Email = $_POST['CustomerMail'];
$Contact = $_POST['CustomerNumber'];
$Comments = $_POST['CustomerComments'];


$message = "Customer First Name: $FirstName\n\n";
$message .= "Customer Last Name: $LastName\n\n";
$message .= "Customer E-mail Address: $Email\n\n";
$message .= "Customer Contact: $Contact\n\n";
$message .= "Customer Comments: $Comments\n\n";

$mail = mail($to, $subject, $message);

}

?>

and my php output code when it is successful and when it fails is

<?php

if ($_POST && !$mail) {
?>
<h1 class="error">Sorry</h1>
<p>There was a problem sending the message. Please try again later.</p>

<?php
} elseif ($_POST && $mail) {
?>
<h1 class="good">Success!</h1>
<p>Your message has been sent. I will get back to you as soon as possible.</p>

<?php } ?>

Kindly can anyone tell me where I went wrong :( Please please

Viewing all articles
Browse latest Browse all 47

Trending Articles