...

View Full Version : Send email - confirm recieved.



jpopuk
08-12-2008, 04:55 PM
Hi,

I am relativley new to PHP and I have a email form script that I need some help with.

It is a simple form which people fill in fields and it then once they click submit it send the form off to an email address inserted within the external php file.

The thing I want to do is add in an extra feature so when some one clicks submit, an email also sends off to the person who filled in the form saying thank you for your email etc. etc.

Here is my php code for the form:


<?php

$my_email = "test@test.co.uk";

$continue = "/";

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = stripslashes($message);

$subject = "Free Consultation";

$subject = stripslashes($subject);

$from_name = "";

if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}

$headers = "From: {$from_name} <{$_REQUEST['email']}>";

mail($my_email,$subject,$message,$headers);

?>

If anyone would know how I would implement this I would be most grateful.

Regards,

Paul

CFMaBiSmAd
08-12-2008, 05:02 PM
At the least an "auto response email" allows spam bot scripts to send nuisance emails to any address they put into the email field. At best (because your code is not validating what was entered) it allows a spam bot script to send anything to anyone it wants.

Just display a "thank you" message on the web page (the visitor is already on your site with their browser open) and please add some validation to the form data to help stop spamming through your mail server.

jpopuk
08-12-2008, 05:04 PM
I know about this, I am trying to do it for some one who I am doing some work for. I did explian this to them but they insisted they have the feature, do you know how it can be achieved?

zackwiny
08-12-2008, 05:05 PM
Hi,

I am relativley new to PHP and I have a email form script that I need some help with.

It is a simple form which people fill in fields and it then once they click submit it send the form off to an email address inserted within the external php file.

The thing I want to do is add in an extra feature so when some one clicks submit, an email also sends off to the person who filled in the form saying thank you for your email etc. etc.

Here is my php code for the form:


<?php

$my_email = "test@test.co.uk";

$continue = "/";

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = stripslashes($message);

$subject = "Free Consultation";

$subject = stripslashes($subject);

$from_name = "";

if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}

$headers = "From: {$from_name} <{$_REQUEST['email']}>";

mail($my_email,$subject,$message,$headers);

?>

If anyone would know how I would implement this I would be most grateful.

Regards,

Paul

How bout this...


$message = "Thank You for your submission";

$subject = "Consultation Received";

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

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

Unless i'm missing something that should work if you just add it on to the end of your script.

If you want to make it so that it checks if the e-mail was received you would need to add something so that it checks your e-mail and searches for the value of $_REQUEST['email']

jpopuk
08-12-2008, 05:17 PM
Hey, that works a treat. Thank you very much. The one thing I would say about this is, with the
{$from_name}. Will the email be from the name entered in the name field?

Webmonkey
08-12-2008, 07:51 PM
No, That would be your name I assume so you would have:


$from_name = 'Automatic mailer';
$my_email = 'noreply@yoursite.com';
$headers = "From: {$from_name} <{$my_email}>";

Hope this helps you :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum