Sending mail form error

Discussion in 'PHP' started by web_master, Aug 22, 2008.

  1. #1
    The form below should send all details to my email but its only sending message and organization ? what wrong with it?
    thanks
    <?php
    ob_start();
           $name=$_POST['name'];
    	   $email=$_POST['email'];
    	   $count=$_POST['count'];
    	   $orga=$_POST['orga'];
    	   $message=$_POST['message'];
    	   
    	   $result = mail($email, $orga, $count, $headers, $message);	   	   	   	   
    	   $headers = "From: $email"; 
    	   	   
    		   include "functions.php"
    		   
    	   if ($name=="" || $email=="" || $orga=="" || $message=="" || $count=="") {
    	   echo "All fields are mandatory!";
    	   } else {
    	   
    	   mail("xxxxxx@googlemail.com", $name, $orga, $message, $header);
    	   
    	   echo "Your message successfuly sent. Now you are redirecting to homepage!.";
    	   }
    	   header("refresh: 2; url=http://www.xxxxxx.org");
    
    
    ?>
    PHP:

     
    web_master, Aug 22, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    The arguments in the mail() function are wrong... see:

    www.php.net/function.mail

     
    nico_swd, Aug 22, 2008 IP
    web_master likes this.
  3. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #3
    nico_swd is right...

    You need to sort out the mail command:

    It should be in this format...
    mail($to, $subject, $message, $from);
    PHP:
    You have also called the variable '$headers' before you've creating the variable!

    I'm also not overly sure why you've created a variable called result as it never gets used?

    What are you trying to do? I'm assuming this is for a contact form?

    If you're wanting to take the information and then email yourself the results you'll need something like this:
    
    <?php
    ob_start();
    
    	$your_email="xxxxxx@googlemail.com";
    	$subject="Subject Line";
    
    
    	$name=$_POST['name'];
    	$email=$_POST['email'];
    	$count=$_POST['count'];
    	$orga=$_POST['orga'];
    	$message=$_POST['message'];
    	$from = "From: " . $email . "\r\n";
    	$build_email = "Name: " . $name . "\nEmail: " . $email$ . "\nCount: " . $count . "\nOrganisation: " . $orga . "\nMessage: " . $message;
    	
    	if ($name=="" || $email=="" || $orga=="" || $message=="" || $count=="")
    		{
    			echo "All fields are mandatory!";
    		} 
    		else
    		{
    			mail($your_email, $subject, $build_email, $from);
    			echo "Your message successfuly sent. Now you are redirecting to homepage!.";
    		}
    	
    	header("refresh: 2; url=http://www.xxxxxx.org");
    ?>
    
    PHP:
     
    aquasonic, Aug 22, 2008 IP
    web_master likes this.
  4. web_master

    web_master Well-Known Member

    Messages:
    649
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Guys thanks so much for replying
    i ll consider ur warnings and let you know the result here.
     
    web_master, Aug 22, 2008 IP