Solved

PHP mail form for website - ability to email sender

Posted on 2009-04-15
2
432 Views
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 = 'email@email.com' ;
$subject = "Workorder Request - Wyandotte" ;
$formurl = "http://www.websiteform.com" ;
$errorurl = "http://www.websiteform.com/erremail.html" ;
$thankyouurl = "http://www.websiteform.com/tyemail.html" ;
$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

0
Comment
Question by:Wyandotte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
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

0
 

Author Comment

by:Wyandotte
ID: 24148653
That worked great. Thanks.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

623 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