Jump to content

Need help with some script


billy nugz

Recommended Posts

ok so here is the code and it works om my server just fine.

[code]<?php
$to      = "[email protected]"; // change to your email address
$name    = $_POST['name'];
$email    = $_POST['email'];
$subject  = $_POST['subject'];
$msg      = $_POST['msg'];
$d        = date('l dS \of F Y h:i:s A');
$sub      = "form to mail";
$headers  = "From: $name <$email>\n"; 
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes      = "Subject: ".$subject."\n";
$mes    .= "Message: ".$msg."\n";
$mes    .= "Name: ".$name."\n";
$mes    .= 'Email: '.$email."\n";
$mes    .= 'Date & Time: '.$d;

if (empty($name) || empty($email) || empty($subject) || empty($msg))
{
    echo "  <h3>Sorry all fields are required.</h3>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
    print "  <h3>Sorry the email address you entered looks like it's invalid.</h3>";
}
else
{
    mail($to, $sub, $mes, $headers);
    print "  <h3><center>Thank you ".$name." for contacting us.<br>We will get back to you as soon as posiable</center></h3>";
}
?>[/code]

But I need to lose the error checking (I will check errors with javascript) and I need to exit to a html page. So once the user clicks send the info sends and then they are directed to a confirm page.

Also is there anyway to change the header so it  reads say mail form or somthing.


Thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/29008-need-help-with-some-script/
Share on other sites

You should do error checking on the client-side (javascript) and on the server side (the PHP). You need to be able to handle clients that do not have javascript enabled.

If you want the processing page to just send the email and then redirect to another page, get rid of the last "print" and replace it with something like this:

header("Location: http://www.example.com/");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.