View Full Version : php plus html auto responder
g_rochford
January 11th, 2007, 10:03 AM
Is there a way after someone enters their email address in my flash contact form I can send them an HTML email automatically? I have the letter i want to send already made and it works fine if i send it from my emali account. But i'd like to miss out the middle part if possible and just "auto respond in html" i guess.
Many thanks
Greg
duncanhall
January 11th, 2007, 10:17 AM
Assuming you have some sort of php script working in the background that sends you the message from the user, just add another function that sends an email to their specified address.
g_rochford
January 12th, 2007, 06:05 AM
Hi Duncan
Yes i am using a php script that looks like this (from an earlier Kirupa tutorial)
<?php
$sendTo = "g_rochford@xxx.co.uk";
$subject = "Contact Form";
$headers = "From: " . $_POST["email"] . "\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$message .= "Message: " . $_POST["msg"] . "\r\n";
$message .= "Name: " . $_POST["name"] . "\r\n";
$message .= "Email: " . $_POST["email"] . "\r\n";
mail($sendTo, $subject, $message, $headers);
if($email=="undefined" || $subject=="undefined" || $message=="undefined"){
echo "Please fill in all the fields";
}else{
echo "Thankyou for registering.";
mysql_connect("localhost", "xxx", "Franzxxx");
mysql_select_db("www_philcampbellmusic_com");
mysql_query("INSERT INTO `Phil` (`email`,`subject`,`message`) VALUES ('$headers','$subject','$message')");
}
?> but im a total newbie to php. Could you suggest something please.
Many thanks again.
Greg
Sinister Rouge
January 12th, 2007, 06:06 AM
you should also check out your host provider as they usually provide a means via the interface to auto respond to emails that are sent to any given address.
duncanhall
January 12th, 2007, 06:26 AM
Er, dude, you've just shown all your database details to anyone who wants it - password, login etc.
I'll post the php script you need in a bit, but I'd edit your post asap if I were you, in case there's some unsavoury characters about.
duncanhall
January 12th, 2007, 06:36 AM
Ok, so this is pretty basic but hopefully you'll get the idea. All I've done really is replicated your email function so that it gets called once the user has successfully signed up:
<?php
$sendTo = "g_rochford@xxx.co.uk";
$subject = "Contact Form";
$headers = "From: " . $_POST["email"] . "\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$message .= "Message: " . $_POST["msg"] . "\r\n";
$message .= "Name: " . $_POST["name"] . "\r\n";
$message .= "Email: " . $_POST["email"] . "\r\n";
mail($sendTo, $subject, $message, $headers);
function autoRespond($user_email) {
$ar_recipient = "$user_email";
$ar_subject = "Thank You For Registering at PhilCampbellMusic.com";
$ar_headers = "From: "someone@philcampbellmusic.com"\r\n";
$ar_headers .= "Reply-To: "someone@philcampbellmusic.com"\r\n";
$ar_message = "Message: " YOUR AUTO RESPONSE MESSAGE HERE";
mail($ar_recipient , $ar_subject , $ar_message, $ar_headers);
}
if($email=="undefined" || $subject=="undefined" || $message=="undefined"){
echo "Please fill in all the fields";
}else{
echo "Thankyou for registering.";
mysql_connect("xxx", "xxx", "xxx");
mysql_select_db("www_philcampbellmusic_com");
mysql_query("INSERT INTO `Phil` (`email`,`subject`,`message`) VALUES ('$headers','$subject','$message')");
autoRespond($_POST["email"]);
}
?>
g_rochford
January 12th, 2007, 06:41 AM
Hi Duncan,
Thanks for your help, thats brilliant.
Also thanks for your concern i"ll change the details to my server now.
Instead of a message, do you know how i can send a complex html document instead of just text?
Greg
duncanhall
January 12th, 2007, 06:53 AM
It shouldn't be too difficult but I haven't done any PHP email stuff for a fair while so the technique eludes me.
Have a look at http://www.phpfreaks.com/tutorials/130/0.php - that seems to have some fairly comprehensive information.
g_rochford
January 15th, 2007, 07:07 PM
Hi Duncan
I tried putting your code in, but it stoped the php form from working at all, and make the bottom half of the code in dreamweaver look wrong???
I dont really understand the syntax but i changed the end of the last line which made it look right again in dreamweaver. I added . "\r\n"
function autoRespond($user_email) {
$ar_recipient = "$user_email";
$ar_subject = "Thank You For Registering at PhilCampbellMusic.com";
$ar_headers .= "From: "someone@philcampbellmusic.com . "\r\n";
$ar_headers .= "Reply-To: "someone@philcampbellmusic.com . "\r\n";
$ar_message .= "Message: " YOUR AUTO RESPONSE MESSAGE HERE . "\r\n";
mail($ar_recipient , $ar_subject , $ar_message, $ar_headers);
}
Sorry to be a pain, but im still confused and lost
Greg
duncanhall
January 16th, 2007, 06:59 AM
Whoops, a bit of concatenation mixup.
Try this:
<?php
$sendTo = "g_rochford@xxx.co.uk";
$subject = "Contact Form";
$headers = "From: " . $_POST["email"] . "\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$message .= "Message: " . $_POST["msg"] . "\r\n";
$message .= "Name: " . $_POST["name"] . "\r\n";
$message .= "Email: " . $_POST["email"] . "\r\n";
mail($sendTo, $subject, $message, $headers);
function autoRespond($user_email) {
$ar_recipient = "$user_email";
$ar_subject = "Thank You For Registering at PhilCampbellMusic.com";
$ar_headers = "From: someone@philcampbellmusic.com \r\n";
$ar_headers .= "Reply-To: someone@philcampbellmusic.com \r\n";
$ar_message = "Message: YOUR AUTO RESPONSE MESSAGE HERE";
mail($ar_recipient , $ar_subject , $ar_message, $ar_headers);
}
if($email=="undefined" || $subject=="undefined" || $message=="undefined"){
echo "Please fill in all the fields";
}else{
echo "Thankyou for registering.";
mysql_connect("xxx", "xxx", "xxx");
mysql_select_db("www_philcampbellmusic_com");
mysql_query("INSERT INTO `Phil` (`email`,`subject`,`message`) VALUES ('$headers','$subject','$message')");
autoRespond($_POST["email"]);
}
?>
g_rochford
January 16th, 2007, 08:50 AM
Thanks Ducan
It works an absolute dream now. Perfect! Many Many thanks! Now if i could just send a complex html I'd be there!
Greg
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.