PHP forwarding from HTML Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mringuk
Forum Newbie
Posts: 1
Joined: Wed Jan 11, 2012 5:50 am

PHP forwarding from HTML Form

Post by mringuk »

I have a Form within my HTML Club Site which works fine. However, as someone new to PHP I am having some difficulty making 2 modifications.

Present Coding:

Code: Select all

<?php

$sendTo = "myemail@mysite.com";

$subject = "Contact from site";

$headers = "From: " . $_POST["name"] . "<" . $_POST["Email"] .">" . "\r\n";

$headers .= "Reply-To: " . $_POST["eEmail"] . "\r\n";

$headers .= "Return-path: " . $_POST["E-mail"];


$message = "The following information has been submitted by " .$_POST["name"] . "\r\n" . "\r\n" . "E-mail Address               : " . $_POST["Email"] . "\r\n" . "First Name     : " . $_POST["name1"] . "\r\n" . "Last Name     : " . $_POST["name2"] . "\r\n" . "Address 1     : " . $_POST["address1"] . "\r\n" . "Address 2    : " . $_POST["address2"] . "\r\n" . "Zip or Post Code : " . $_POST["post_code"] . "\r\n" . "Comments     : " . $_POST["comments"];


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

header( 'Location: http://www.mysite.com/thanks.html' ) ;

?>
I would like to send a BCC e-mail to a second recipient. I can send to a second e-mail by changing that first line:

$sendTo = "myemail@mysite.com,myemail2@mysite.com";

That also works but I can't get it to BCC:

My second wish is to send the e-mail back to the person filling in the Form, $_POST["Email"] How is this done?

Any advice would be most appreciated
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: PHP forwarding from HTML Form

Post by twinedev »

You just need to add it into the $headers variable....

Code: Select all

$headers .= 'Bcc: myemail2@mysite.com, '.$_POST['Email']."\r\n";
Make sure you at least do some checking to make sure that the e-mail they post looks like a valid address. at the very least:

Code: Select all

if (!preg_match('/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/i',$_POST['Email']) {

	// INVALID E-MAIL ADDRESS....

}
Also be aware of people using this to spam other people by entering in other people's address, which could possibly create issues for you (ie, they have a bot fill out the form to e-mail someone 1000 times, then the recipient notifies your hosting provider, next thing you know, may be saying to yourself "hmm can't browse to my site no more!")

More examples of mail() use can be found here: http://kr2.php.net/manual/en/function.mail.php

-Greg
Post Reply