email script

Discussion in 'PHP' started by cavendano, Mar 6, 2008.

  1. #1
    How can i fix this? I have a form that outputs all this data but I want it sent in one email. The message of the email should include $First, $Last, $email, $phone, $request, $order and comments.
    Any help would be appreciated...
    <?
    $memail = "myemail@email.com";
    $subject = $_POST["subject"];
    $recipient = $_POST["recipient"];
    $redirect = $_POST["redirect"];
    $missing= $_POST['missing_fields_redirect'];
    $First = $_POST["First"];
    $Last = $_POST["Last"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $request = $_POST["Request"];
    $order = $_POST["Order Number"];
    $comments = $_POST["comments"];
    
    if ($First =='' || $Last=='' || $email=='' || $request=='' || $comments==''){
    echo "Please fill in the required fields.";
    	
    
    }else{
    mail( "$memail", "$subject",
      $comments, "From: $email" );
    }
    ?>
    PHP:

     
    cavendano, Mar 6, 2008 IP
  2. Dagon

    Dagon Active Member

    Messages:
    122
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #2
    <?
    $memail = "myemail@email.com";
    $subject = $_POST["subject"];
    $recipient = $_POST["recipient"];
    $redirect = $_POST["redirect"];
    $missing= $_POST['missing_fields_redirect'];
    $First = $_POST["First"];
    $Last = $_POST["Last"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $request = $_POST["Request"];
    $order = $_POST["Order Number"];
    $comments = $_POST["comments"];
    
    if ($First =='' || $Last=='' || $email=='' || $request=='' || $comments==''){
    echo "Please fill in the required fields.";
    	
    
    }else{
    $comments = "First: $First\nLast: $Last\nEmail: $email...(and so on)\n\n$comments";
    mail( "$memail", "$subject", $comments, "From: $email" );
    }
    ?>
    PHP:
     
    Dagon, Mar 6, 2008 IP
  3. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #3
    If formatting isn't of the highest priority, you could use this:

    <?php
    
    function print_array_nodes( $TheArray ) {
    	echo "<table border=1>\n";
    	$Keys = array_keys( $TheArray );
    	foreach( $Keys as $OneKey ) {
    		echo "<tr>\n";
    		echo "<td bgcolor='#727450'>";
    		echo "<B>" . $OneKey . "</B>";
    		echo "</td>\n";
    		echo "<td bgcolor='#C4C2A6'>";
    		if ( is_array($TheArray[$OneKey]) )
    		print_array_nodes($TheArray[$OneKey]);
    		else
    		echo $TheArray[$OneKey];
    		echo "</td>\n";
    		echo "</tr>\n";
    	}
    	echo "</table>\n";
    }
    
    $memail = "myemail@email.com";
    $subject = $_POST["subject"];
    $recipient = $_POST["recipient"];
    $redirect = $_POST["redirect"];
    $missing= $_POST['missing_fields_redirect'];
    $First = $_POST["First"];
    $Last = $_POST["Last"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $request = $_POST["Request"];
    $order = $_POST["Order Number"];
    $comments = $_POST["comments"];
    if ($First =='' || $Last=='' || $email=='' || $request=='' || $comments==''){
    	echo "Please fill in the required fields.";
    } else {
    	//STORE OUTPUT
    	ob_start();
    	//TRANSLATE ARRAY INTO TABLE
    	print_array_nodes($_POST);
    	//ASSIGN DATA TO A VARIABLE
    	$data = ob_get_contents() ;
    	//REMOVE EXTRA LINE BREAKS / NEW LINES
    	$data = ereg_replace("\r","",$data);
    	$data = ereg_replace("\n","",$data);
    	//CLEAN OUT THE OUTPUT BUFFER
    	ob_clean();
    	$headers  = 'MIME-Version: 1.0' . "\n";
    	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
    	//SEND THE MESSAGE
    	mail("$memail","$subject",$data,$headers);
    }
    ?>
    PHP:
    This will allow you to add more information to your form post and not worry about including it into the email message.

    -Bing
     
    bpasc95, Mar 6, 2008 IP