PhP e-mail help

I am needing help with Breaking down this code and understanding it. What I am needing to do is when they win a bid on this site it sends an e-mail when it sends the e-mail it sends everything from all venders and there winning stuff as well .
Here is the code take a look and see

$contents = “Congratulations,\n\nYou are receiving this email from Biducation to inform you that your bid was accepted. Your contact is $bidfname $bidlname and they can be reached at $bidemail or by phone at $phone Be sure to contact Mr or Mrs $bidlname to finalize this transaction. \n\n Thank you for the difference you make in our communitites by doing business with communitites through Biducation,\n\nThe Biducation Team on behalf of $schoolname.”;
if($contents != “”)
{
$headers = “From: $from”;
mail($to,$subject,$contents,$headers);
//echo $contents;
/*
require_once ‘includes/Mail/mail.php’;
$host = “mail.syndeoclients.com”;
$username = "[email protected]";
$password = “synd30”;

            $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
            $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
            
            $mail = $smtp->send($to, $headers, $contents);
            
            if (PEAR::isError($mail)) {
			echo $mail->getMessage();
            }
             */
            
            $q = "update tbl_bids set bid_status = '5', bid_awarded_to = \"$winnerid\", bid_payment_status = '0' where bid_id = \"$bid\"";
            mysql_query($q);
            
            echo "The award process has been completed and an email has been sent to the bid owner and the winning vendor.  Thank you.";
            
            
        }
    }
    else {
        echo "You didn't select a recipient.  Please use your browser's back button to return to the previous page.";
    }

}

In future, try and put code in proper code format to make it easier to read also note that when writing your own code, always comment it like I’m about to in order to enable other people to read the code more efficiently. Here’s a break down of the code:

[php]
// Check if there is anything within the $contents variable
if($contents != “”)
{
//Create the headers variable and declare who the email is from. $from would be named somewhere earlier i.e. $from = “Admin”;
$headers = “From: $from”;
//Send the email
mail($to,$subject,$contents,$headers);
//echo $contents;
/*

            //Include the mail.php file
            require_once 'includes/Mail/mail.php';

            //Create the db host
            $host = "mail.syndeoclients.com";

            //Set username
            $username = "[email protected]";

            //Set password (Hope this isn't a real password for the above email!)
            $password = "synd30";
            
            //Set the headers to the email
            $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);

            //Connect
            $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
            
            //Put the email command into the $mail variable
            $mail = $smtp->send($to, $headers, $contents);
            

            //Check if there is an error
            if (PEAR::isError($mail)) {

        //There is an error, output it
        echo $mail->getMessage();
            }
             */
            
            //Prepare the updating of the db
            $q = "update tbl_bids set bid_status = '5', bid_awarded_to = \"$winnerid\", bid_payment_status = '0' where bid_id = \"$bid\"";

            //Update db (Note that this function is now deprecated - see php.net for more info and start using PDO/MySQLi)
            mysql_query($q);
            
            //Output success message
            echo "The award process has been completed and an email has been sent to the bid owner and the winning vendor.  Thank you.";
            
            
        }
    }
  
    //Output an error
    else {
        echo "You didn't select a recipient.  Please use your browser's back button to return to the previous page.";
    }

}
[/php]

THanks you rock

Sponsor our Newsletter | Privacy Policy | Terms of Service