Forum Moderators: coopster

Message Too Old, No Replies

Send email copy

Is this something that can be programmed

         

martinstan

1:48 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



Hi
I can muddle through with PHP at the minute with a basic understanding. What I have a simple form that collects name, address, email and enquiry. When the submit button is pressed then an email is sent to me. Is it possible (I'm sure it must be) for a copy of the same email to be sent to the person who has just filled in the form? Below is the PHP code:


<?php
$to = "me@me.com";
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$d = date('l dS \of F Y h:i:s A');
$sub = "Contact from website";
$headers = "From:" .$email."\n";
$mes .= "Name: ".$name."\n";
$mes .= "Tel: ".$tel."\n";
$mes .= 'Email: '.$email."\n";
$mes .= "Message: ".$msg."\n";

if (empty($name) ¦¦ empty($tel) ¦¦ empty($email) ¦¦ empty($msg))
{
echo " <h3>Sorry all fields are required.</h3>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <h3>Sorry the email address you entered looks like it's invalid.</h3>";
}
else
{
$mail = mail("$to", "$sub", "$mes", "$headers");
print " <h3><center>Thank you ".$name." for contacting me.<br>I will get back to you as soon as possible</center></h3>";
}
?>


Many thanks
Martin

d40sithui

2:13 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



$to = "me@me2.com, you@you.com, him@him.com";
you get the idea (just separate with commas).

martinstan

2:35 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



Hi
Thanks for reply, but I'm not sure that would work. Their email address would need to be pulled from the email field in the form (that they are entering their email address into) and sent dynamically. Hope that makes sense.
Martin

dreamcatcher

3:03 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should be ok:

$mail = mail("$to,$email",$sub,$mes,$headers);

Or just add another mail function:

mail("$email", "$sub", "$mes", "$headers");

dc

martinstan

3:21 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



Thanks for the help so far.
I think I'm following, but sorry for adding this extra bit. Ideally the copy of the email sent to the person who has filled in the form could contain within the body of the message, or perhaps the subject, an idication that the email is a copy. So for instance it could say -

"Thankyou for contacting me. This is a copy of the email that you have sent and I'll respond as soon as I can."

(Then the body of the email)

I suppose almost like an autoresponse.

Thanks again

jatar_k

5:16 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



then just send 2, call the mail function twice, if you want different content

d40sithui

5:19 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



$to.= ",".$email;

jatar_k

5:31 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if the email only goes to you then just slap the "this is a copy" text right in there and then just ignore it yourself

just add the Cc to the headers

$to = "me@me.com";
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$d = date('l dS \of F Y h:i:s A');
$sub = "Contact from website";
$headers = "From:" .$email."\r\n";
$headers .= "Cc: $email\r\n";
$mes .= "Name: ".$name."\n";
$mes .= "Tel: ".$tel."\n";
$mes .= 'Email: '.$email."\n";
$mes .= "Message: ".$msg."\n";

you are supposed to use \r\n to separate your headers, not just \n, though I use both

you also don't need to use " around vars, like you do here

$mail = mail("$to", "$sub", "$mes", "$headers");

just throw the vars in there

$mail = mail($to, $sub, $mes, $headers);

Habtom

6:06 am on Aug 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it possible (I'm sure it must be) for a copy of the same email to be sent to the person who has just filled in the form?

$headers .= "Cc: $email\r\n";

Not a big deal, but if you want to hide the fact the email was copied to someone else, you can do the following:

$headers .= "Bcc: $email\r\n";

Habtom

martinstan

8:59 am on Aug 30, 2007 (gmt 0)

10+ Year Member



Wow!
Thanks to everyone for their input. I've managed to get it working.

Martin