I can give you the script to send an email from php...
Save this page as email_worker.php
Code:
<?php
if(isset($_POST['email'])) {
$email_to = "support@yoursite.co.za";
$email_subject = "Hello There";
function died($error) {
$_SESSION['pageresult'] = "Error. Email has NOT been sent. Please check you have filled in all the fields.";
header("Location: http://www.yoursite.co.za/email_worker.php");
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
$_SESSION['pageresult'] = "Error. Email has NOT been sent. Please check you have filled in all the fields.";
header("Location: http://www.yoursite.co.za/email_worker.php");
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$message = $_POST['message']; // 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($message) < 2) {
$error_message .= 'The Message you entered does 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 .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
$_SESSION['pageresult'] = "Email has been sent. Thank you we will contact you shortly.";
header("Location: http://www.yoursite.co.za/email_worker.php");
}
?>
Then save this page as what ever you like..
Code:
<form name="contactform" method="post" action="email_worker.php">
<table width="400">
<tr>
<td>
<label for="first_name">First Name:</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" style="width:100%">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name:</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" style="width:100%">
</td>
</tr>
<tr>
<td>
<label for="email">Email Address:</label>
</td>
<td>
<input type="text" name="email" maxlength="80" style="width:100%">
</td>
</tr>
<tr>
<td>
<label for="comments">Message:</label>
</td>
<td>
<textarea name="message" maxlength="1000" cols="25" rows="6" style="width:100%"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td style="text-align:center">
<input type="submit" value="Submit" style="height: 30px; width:101%">
</td>
</tr>
</table>
</form>
Bookmarks