PHP mail form for website - ability to email sender

Posted on 2009-04-15
Last Modified: 2013-11-10
Attached is the code for a PHP mail form that I am currently running. What I want to do I believe is pretty simple I just can't figure it out. I currently have an email address that these forms are sent to. I have a spot in the form for the person submitting the work order to type in their address. This address is the address that the email comes from so that we can reply to them. I want the form to pull that address and send it there as well. So basically I want the form sent to the address in the mailto and whatever is typed into $email.

$mailto = '' ;

$subject = "Workorder Request - Wyandotte" ;

$formurl = "" ;

$errorurl = "" ;

$thankyouurl = "" ;

$uself = 0;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;

$name = $_POST['name'] ;

$email = $_POST['email'] ;

$username = $_POST['username'] ;

$department = $_POST['department'] ;

$problem = $_POST['problem'] ;

$priority = $_POST['priority'] ;

$reboot = $_POST['reboot'] ;

$comments = $_POST['comments'] ;

$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {

	header( "Location: $formurl" );

	exit ;


if (empty($name) || empty($email) || empty($username) || empty($comments)) {

   header( "Location: $errorurl" );

   exit ;


if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {

	header( "Location: $errorurl" );

	exit ;


if (get_magic_quotes_gpc()) {

	$comments = stripslashes( $comments );


$messageproper =

	"Name of sender: $name\n\n" .

	"Email of sender: $email\n\n" .

	"Name of user with problem: $username\n\n" .

	"Department: $department\n\n" .

	"Problem: $problem\n\n" .

	"Priority Level: $priority\n\n" .

	"Has the user rebooted their computer?: $reboot\n\n" .

	"------------------------- PROBLEMS -------------------------\n\n" .

	$comments .

	"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,

	"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );

header( "Location: $thankyouurl" );

exit ;


Open in new window

Question by:Wyandotte
LVL 16

Accepted Solution

Chris Harte earned 500 total points
ID: 24148377
Add your recipients to a variable $to, seperated by a comma, and use that in your send to field.


$to = $mailto.','. $email;        

mail($to, $subject, $messageproper,

Open in new window


Author Comment

ID: 24148653
That worked great. Thanks.

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now