bradley097 Posted March 15, 2010 Share Posted March 15, 2010 Hey, I'm a web designer that recently decided to go freelance, but I have little understanding of PHP and require help with some PHP code I use for my comment forms. I have two forms on one of my pages and require them to go to different e-mail addresses. Here is the PHP code before my DOCTYPE and HTML: <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['contactname']) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = '[email protected]'; $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'From: Contact Form <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> This is the first form, I want this to go to [email protected] (Domain hasn't been set up yet but it works with another e-mail address) <?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p><strong>Comment Successfully Sent!</strong></p> <p>Thank you <strong><?php echo $name;?></strong> your comment has been placed in que for admin review and will be posted shortly.</p> <?php } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <div> <label for="name"><strong>*Name:</strong></label> <input type="text" size="30" name="contactname" id="contactname" value="" class="required" /> </div> <div> <label for="email"><strong>*Email:</strong></label> <input type="text" size="30" name="email" id="email" value="" class="required email" /> <p>This field is kept private and will not be shown publicly.</p> </div> <div> <label for="message"><strong>*Comment:</strong></label> <textarea rows="5" cols="50" name="message" id="message" class="required"></textarea> </div> <p><input type="submit" value="Post" name="submit" /></p> </form> Then the second form I want to go to [email protected], I used the exact same code as the first form, and was hoping there was a possibility to have them send to different emails without having to link to an external PHP file. thanks, Brad Link to comment https://forums.phpfreaks.com/topic/195238-web-developer-newbie-needs-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.