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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

17 Experts available now in Live!

Get 1:1 Help Now