Log in

View Full Version : php form auto response



hamfast
01-23-2008, 04:01 PM
Hello there

I've got a php form designed to request simple information from web site traffic (their name, address etc, email ) - how complicated is it to generate an automatic email response to say thanks to those who have completed the form?

Thanks
H

TimFA
01-23-2008, 04:20 PM
Not hard at all, just do what you did with the mail() to send it to you, something like this will do.



$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$autoreply="Thank you for your time, $name. Your message/comment is replied to you
below\n\n$message\n\nThis is an automated reply.";
$subject="Thank you for your submission $name!";

mail($email, $subject, $autoreply);


Of course it would need to be edited so as no conflicts with yours, and so that it goes with what your form names are, your message, etc. It should work though.

Tim

hamfast
01-24-2008, 03:13 PM
Tim

Thanks for the response - I've had a go (several actually) at getting this to work but something's going wrong as I'm not getting the autoresponse

Could you point me in the right direct by any chance.

Cheers
H

TimFA
01-24-2008, 03:32 PM
I'm having problems looking up the mail() function, mail.google.com and mail.yahoo.com are there to much lol. Anyways, it just it me can mail even be used more than once? In the same script that is...

thetestingsite
01-24-2008, 04:18 PM
Actually, yes it can be used as many times as you need it to. Here is what you need to do to your script:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>

<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


$autoTo = "me@mydomain.com";
$autoreply = "Thanks for you submission!"; //change this to your message

mail($autoTo, "Auto Reply Subject", $autoreply, 'From: noreply@domain.com');


mail("email@email.co.uk", $subject, $message, $from);


?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="http://www.google.co.uk"> Next Page </a>
</p>

</body>
</html>


Hope this helps.

hamfast
01-25-2008, 12:14 PM
That's cracked it - brilliant. Thanks

MKjunior
10-27-2008, 10:11 AM
Hi everyone, i was just wondering if someone could give me a starting point on where to begin with the auto responder. I have done some research into auto response in PHP but cant get my head around it.

I have a basic contact form which sends to the mailer, but i need it to send an auto response, can anyone help?


<?php

$myemail = "Myemailgoes here";


$yourname = check_input($_POST['yourname'], "Enter your name");
$email = check_input($_POST['email'], " Enter your email");
$number = check_input($_POST['number']);
$comments = check_input($_POST['comments']);


if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}


$messageone = "Hello!

Your contact form has been submitted by:

Name: $yourname
E-mail: $email
number: $number



Comments:
$comments

End of message
";

$messagetwo = "contact info";

mail($myemail, $messagetwo, $messageone);

header('Location: index.html');
exit();



function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<b>Please correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>
<?php
exit();
}
?>

MKjunior
10-27-2008, 02:07 PM
I have added a little code to the bottom of my code, and to no avail. If anyone could help me that would be great


<?php

$myemail = "martin.s.kilner@googlemail.com";


$yourname = check_input($_POST['yourname'], "Enter your name");
$email = check_input($_POST['email'], " Enter your email");
$number = check_input($_POST['number']);
$comments = check_input($_POST['comments']);

$from_name = "Martin Kilner";

$headers = "From: {$from_name} <{$myemail}>";


if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}


$messageone = "Hello!

Your contact form has been submitted by:

Name: $yourname
E-mail: $email
number: $number



Comments:
$comments

End of message
";

$messagetwo = "contact info";

mail($myemail, $messagetwo, $messageone);

header('Location: index.html');
exit();



function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{





$messagethree = "Thank You for your submission";

$subject = "Received";

$headers = "From: {$from_name} <{$myemail}>";

mail($_REQUEST['email'],$subject,$messagethree,$headers);

?>
<html>
<body>

<b>Please correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>


<?php
exit();
}
?>


If anyone could help me out, i would appreciate it. been trying to figure it out for ages now. :(

rangerjoe
11-06-2008, 10:40 PM
Hey, just wondering if you've received an answer on this...I'm looking to generate an email to a user who has filled out my form as well...

Let me know, thanks!