jmar4c
04-26-2012, 01:56 AM
I am editing a "Contact Us" PHP script, I know nothing about PHP so it's just trial and error. Right now after I fill out the form and hit send, it sends to the proper email address but everything included in the form disappears.
I get this error:
notice: Undefined index:cf_name in contact.php on line 2
notice: Undefined index:cf_email in contact.php on line 3
notice: Undefined index:cf_message in contact.php on line 4
Here is the PHP script:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'WITHHELD';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index-4.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
Here is the relevant form code:
<h2>Contact Form</h2>
<form action="contact.php" method="post" id="contacts-form" class="contact-form">
<fieldset>
<div class="rowElem">
<label>Name:</label>
<input type="text" class="text" name="cf_name">
</div>
<div class="rowElem">
<label>E-mail:</label>
<input type="email" class="text" name="cf_email">
</div>
<div>
<label>Message:</label>
<textarea cols="1" rows="1" name="cf_message">
</textarea>
</div>
<div class="button"><a href="#" onClick="document.getElementById('contacts-form').submit()">send</a><a href="#" onClick="document.getElementById('contacts-form').reset()">clear</a></div>
</fieldset>
</form>
I feel like the fix is really simple, but I am not a coder so I can't find the solution. Hopefully one of you brilliant individuals will be able to. Thanks in advance!
I get this error:
notice: Undefined index:cf_name in contact.php on line 2
notice: Undefined index:cf_email in contact.php on line 3
notice: Undefined index:cf_message in contact.php on line 4
Here is the PHP script:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'WITHHELD';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index-4.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
Here is the relevant form code:
<h2>Contact Form</h2>
<form action="contact.php" method="post" id="contacts-form" class="contact-form">
<fieldset>
<div class="rowElem">
<label>Name:</label>
<input type="text" class="text" name="cf_name">
</div>
<div class="rowElem">
<label>E-mail:</label>
<input type="email" class="text" name="cf_email">
</div>
<div>
<label>Message:</label>
<textarea cols="1" rows="1" name="cf_message">
</textarea>
</div>
<div class="button"><a href="#" onClick="document.getElementById('contacts-form').submit()">send</a><a href="#" onClick="document.getElementById('contacts-form').reset()">clear</a></div>
</fieldset>
</form>
I feel like the fix is really simple, but I am not a coder so I can't find the solution. Hopefully one of you brilliant individuals will be able to. Thanks in advance!