troubleshooting Question

why this php script is not working?

Avatar of glepiza
glepiza asked on
PHPWeb Servers
8 Comments1 Solution204 ViewsLast Modified:
Hi Experts,

I've been digging around this script to send emails, but I really don't know why it is not working. Everything from my point of view looks correct. Well, after couple hours trying I decided it was time to ask an expert to help me to figure why is wrong with it.  My page reads php.

Thanks in advance.

<?php  
 
if(isset($_POST['submit'])) {  
  
 
    if(trim($_POST['fstname']) == '') {  
        $hasError = true;  
    } else {  
        $name = trim($_POST['fstname']);  
    }  
      
   if(trim($_POST['sport']) == '') {  
        $hasError = true;  
    } else {  
        $subject = trim($_POST['sport']);  
    }
	
    if(trim($_POST['subject']) == '') {  
        $hasError = true;  
    } else {  
        $subject = trim($_POST['subject']);  
    }  
      
 
    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']);  
    }  
      
 
    if(trim($_POST['message']) == '') {  
        $hasError = true;  
    } else {  
        if(function_exists('stripslashes')) {  
            $comments = stripslashes(trim($_POST['message']));  
        } else {  
            $comments = trim($_POST['message']);  
        }  
    }  
  
 
    if(!isset($hasError)) {  
        $to = 'xxx@email.com'; 
        $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";  
        $headers = 'From: My Site <'.$to.'>' . "\r\n" . 'Reply-To: ' . $email;  
  
        mail($to, $subject, $body, $headers);  
        $emailSent = true;  
      
}  
?>
ASKER CERTIFIED SOLUTION
Cornelia Yoder
Artist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros