Page 1 of 1

PHP EMAIL ANY ONE AN EXPERT?

Posted: Thu Jun 26, 2008 1:50 pm
by sebpearce
what im trying to do is when a a submit button is pressed on a form i want the script to handle it by sending a thank you email to the preson sending which i have got done no problems, but also to send an email to an email addres i would like it to go to with all the field data enterd in the form present in the email. the script i have thrown up so far is this.


it sends the email as requested to the person sending the script and it also sends an email to the email addres i want it to send it to.. damien@boltonpropertydevelopments.com with all the field value's there but the data along with it isnt, so it looks like theform was not filled in

just displays as:
Values submitted by the user:
name:
email:
contact:
address:
postcode:
message: Message here....
submit: submit information
recipient: damien@boltonpropertydevelopments.com
subject: Mail Sent Via Website :arrow: :arrow:


if any one knows how to write a php script that can do this it would be mega if you could help me out


i have posted a test page up online im working with thats at http://www.boltonpropertydevelopments.com/contact1.php

on the actual website i have a diffrent page http://www.boltonpropertydevelopments.com/contact.html

and that runs the script through <form action="sucess1.php" method="post"> this works fine and sends all the deatils i want but does not send a thankyou we will be in touch soon email to the client that i would like.

Code: Select all

 
 
<?php # script 1.00 - contact.php
 
 
 
if (isset($_POST['submit'])) { // HANDEL THIS FORM
 
$message = NULL;
 
// name check.
if (strlen($_POST['name']) > 0) {
$name = TRUE;
} else {
$name = FALSE;
echo '<p>Please enter your name</p>';
}
// email check. 
if (strlen($_POST['email']) > 0) {
$email = TRUE;
} else {
$email = FALSE;
echo '<p>Please enter your email address</p>';
}
// Contact number check.
if (strlen($_POST['contact']) > 0) {
$contact = TRUE;
} else {
$contact = FALSE;
echo '<p>Please enter a contact number</p>';
} 
 
 
if ($name && $email && $contact) { // if all is filled out.
// complete the request.
 
 
// send an email to sender.
$body = "Thank you '{$_POST['name']}' for your message left on our site boltonpropertydevelopments.com";
mail ($_POST['email'], $body, 'As soon as we check the machine we will be in touch shortly
Thank you, The Team.');
 
 
header ('Location: sucess.html');
exit();
 
} else { //something's not filled in i requested or need.
$message .= '<p>Please try again.
</p>';
}
 
}
 
// Print out error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message,
',</font>';
}
 
 
?>
 
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){
 
$msg="Values submitted by the user:\n";
foreach($_POST as $key => $val){
if (is_array($val)){
$msg.="Item: $key\n";
foreach($val as $v){
$v = stripslashes($v);
$msg.=" $v\n";
}
} else {
$val = stripslashes($val);
$msg.="$key: $val\n";
}
}
$recipient="damien@boltonpropertydevelopments.com";
$subject="Form Mail from boltonpropertydevelopments.com";
error_reporting(0);
if (mail($recipient, $subject, $msg)){
echo "";
echo nl2br($input);
} else
echo "";
} else
echo "";
?> 
 

below is the form im working with on the page

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 
 
<fieldset><legend></legend>
 
<br>
 
<input type="text" name="name"> 
Name
<br>
 
<input type="text" name="email"> 
Email
<br>
 
<input type="text" name="contact"> 
Contact Number
<br>
 
<input type="text" name="address"> 
Address
<br>
 
<input type="text" name="postcode"> 
PostCode
</p>
<p> Please leave a brief message and we will shortly be in touch
<br>
<TEXTAREA NAME ="message" Cols=60 ROWS=10 WRAP class="style2">Message here....</TEXTAREA>
</p>
</fieldset> 
 
<div align="center">
<p>
<input type="submit" name="submit" value="submit information" />
 
</p>
</div>
 
<input name="recipient" type="hidden" id="recipient" value="damien@boltonpropertydevelopments.com">
<input name="subject" type="hidden" id="subject" value="Mail Sent Via Website">
 
 
 
</form>
 

Re: PHP EMAIL ANY ONE AN EXPERT?

Posted: Thu Jun 26, 2008 3:50 pm
by dyluck
I'm no expert, but I would test your logic statement here:
if ($name && $email && $contact) {
}
First of all that statement doesn't have a logic behind it. Its just saying if (name and email and contact) (which is probably failing the statement because there is nothing to compare... and bypassing sending that email.

I also wouldn't trust peoples posts... I would test the post for symbols and make sure the email syntax is correct first and then set the results to variables... Also get yourself a captcha for the form.. you don't want bots sending you piles of junk!

I would also send both emails from either your form site or your success.html to reduce the redundancy.

Try something like this:
if (empty($name) || empty($email) || empty($contact)) {
Display Errors } else { send both emails }

this statement says if any of these variables are empty then display an error else send BOTH emails :)

Hope that works for you...