jponte Posted February 24, 2010 Share Posted February 24, 2010 Hi, I submita form to a page were I insert everything to the DB and also mail info to an email address. I do a couple of checks before inserting into the DB. At the end I mail the info no matter what due that is not within the IF statements. I would like to inlcude the code but the email portion is long and would not like to repeat the coed twice. How would I go about incorporating it? He is the code. This is the mail portion: // Mail PHP After Adding to DB require_once('class.phpmailer.php'); include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $body = "<br><strong>RMA info</strong> <br> RMA Date: $RMADate <br> RMA Number: $RMANumber <br><br> <strong>Customer info </strong> <br> Customer ID: $CustomerID <br> Contact Name: $CustomerName <br> <strong>Device information </strong><br> Device CTN: $DevicePhone <br> Device IMEI: $DeviceIMEI <br> Device Make: $DeviceType <br> Device SIM: $SIMCard <br> Device Model: $DeviceModel <br> Defect Description: $DescDefect<br><br> <strong>Troubleshooting </strong><br> Reset Device? $ResetDevice <br> Software Reload? $SoftwareReload <br> Wipe Device? $WipeDevice <br> Other? $TroubNotes <br> Additional Troubleshooting: $TroubNotes <br><br> <strong>Shipping Information </strong><br> Attention: $ShipAttention <br> Contact CTN: $ShipPhone <br> Contact Email: $ShipEmail <br><br> Address: $ShipStreet <br> Additional info: $ShipAddinfo <br> City: $ShipCity <br> Province: $ShipProv <br> Postal Code: $ShipPCode <br> Additional Notes $ShipAddNotes <br><br> Error: $errorqry <br>(If blank no error has been reported wrting to DB)"; //$body = file_get_contents('contents.html'); //$body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "smtp.com"; // SMTP server $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "smtp.com"; // sets the SMTP server $mail->Port = 25; // set the SMTP port for the GMAIL server $mail->Username = "@"; // SMTP account username $mail->Password = "i"; // SMTP account password $mail->SetFrom('@', 'ESC RMA Team'); //Possibility to CC the customer //$mail->Addcc ("$CustomerEmail "); $mail->AddReplyTo("@","First Last"); $mail->Subject = "New Submited RMA Form - $RMANumber"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = "@ "; $mail->AddAddress($address, "John Doe"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "<center><br>Your information has been sent to ESC. You will shortly receive an email with the ESC ticket number that has been assigned to this RMA.<br> Please keep the RMA form number for your records: <br><br><h3><b>$RMANumber</b></center></h3>"; } ?> And here are the IF Statements: <?php //Set variables for database access $Host = "localhost"; $User = "root"; $PasswordDB = "escrma"; $DBName = "rma_portal"; //Connect to Database $Link = mysql_connect ($Host, $User, $PasswordDB); mysql_select_db("rma_portal") or die(mysql_error()); //RMA info Vars $RMADate = $_POST['RMADate']; $RMANumber = $_POST['RMANumber']; //Customer Info Vars $CustomerID = $_POST['CustomerID']; $CustomerName = $_POST['CustomerName']; //Device Info Vars $DevicePhone = $_POST['DevicePhone']; $DeviceType = $_POST['DeviceType']; $DeviceModel = $_POST['DeviceModel']; $DeviceColor = $_POST['DeviceColor']; $DeviceIMEI = $_POST['DeviceIMEI']; $DescDefect = $_POST['DescDefect']; //Troubleshooting Vars $ResetDevice = isset ($_POST['Troubleshooting']['ResetDevice']) ? 'Y' : 'N'; $SoftwareReload = isset ($_POST['Troubleshooting']['SoftwareReload']) ? 'Y' : 'N'; $WipeDevice = isset ($_POST['Troubleshooting']['WipeDevice']) ? 'Y' : 'N'; $TroubOther = isset ($_POST['Troubleshooting']['TroubOther']) ? 'Y' : 'N'; $TroubNotes = $_POST['TroubNotes']; //Shipping Info Vars $ShipAttention = $_POST['ShipAttention']; $ShipPhone = $_POST['ShipPhone']; $ShipEmail = $_POST['ShipEmail']; $ShipStreet = $_POST['ShipStreet']; $ShipAddinfo = $_POST['ShipAddinfo']; $ShipCity = $_POST['ShipCity']; $ShipProv = $_POST['ShipProv']; $ShipPCode = $_POST['ShipPCode']; $ShipAddNotes = $_POST['ShipAddNotes']; // Collects data from rma_contact table $contactqry = mysql_query("SELECT * FROM rma_contact WHERE Cont_Attention = '$ShipAttention' AND Cont_Email = '$ShipEmail'") or die('Could not run query: ' . mysql_error()); // puts the "rma_contact" info into the $contactinfo array if found $contactinfo = mysql_fetch_assoc($contactqry); $ContactIDVal = $contactinfo['Contact_ID']; if(!isset($ContactIDVal)){ $Query2 = "INSERT into rma_contact (Cont_Attention, Cont_Phone, Cont_Email, Cont_Address, Cont_Add_Address, Cont_City, Cont_Prov, Cont_Postal, Cont_Add_Info) values ('$ShipAttention', '$ShipPhone', '$ShipEmail', '$ShipStreet', '$ShipAddinfo', '$ShipCity', '$ShipProv', '$ShipPCode', '$ShipAddNotes')"; if (mysql_db_query ($DBName, $Query2, $Link)) { //Get the generated ID for Contact_ID $Gen_Contact_ID = mysql_insert_id(); $Query = "INSERT into rma_devices values ('$RMANumber', '$CustomerID', '$RMADate', '$DevicePhone', '$DeviceType', '$DeviceModel', '$DeviceIMEI', '$DeviceColor', '$DescDefect', '$ResetDevice', '$SoftwareReload', '$WipeDevice', '$TroubOther', '$TroubNotes', '$Gen_Contact_ID')"; } else {print ("<Center>There was a problem saving the RMA form to the database<br>Please contact ESC at 1-877-939-3282\n"); echo "<BR><BR>Error message = ".mysql_error(); echo "<br><br></center>"; $errorqry = mysql_error(); } if (mysql_db_query ($DBName, $Query, $Link)) { } else {print ("<Center>There was a problem saving the RMA form to the database<br>Please contact ESC at 1-877-939-3282\n"); echo "<BR><BR>Error message = ".mysql_error(); echo "<br><br></center>"; $errorqry = mysql_error(); } } else{ $Gen_Contact_ID = $contactinfo ['Contact_ID']; $Query3 = "INSERT into rma_devices values ('$RMANumber', '$CustomerID', '$RMADate', '$DevicePhone', '$DeviceType', '$DeviceModel', '$DeviceIMEI', '$DeviceColor', '$DescDefect', '$ResetDevice', '$SoftwareReload', '$WipeDevice', '$TroubOther', '$TroubNotes', '$Gen_Contact_ID')"; if (mysql_db_query ($DBName, $Query3, $Link)) { } else {print ("<Center>There was a problem saving the RMA form to the database<br>Please contact ESC at 1-877-939-3282\n"); echo "<BR><BR>Error message = ".mysql_error(); echo "<br><br></center>"; $errorqry = mysql_error(); } } if (!$link = mysql_connect('localhost', 'root', 'escrma')) { echo 'Could not connect to mysql'; exit; } if (!mysql_select_db('rma_portal', $link)) { echo 'Could not select database'; exit; } print_r ($_POST); //print ("<br>The Query2 is:<BR>$Query2<P>\n"); //print ("<br>The Query1 is:<BR>$Query<P>\n"); //print ("<br>The Query3 is:<BR>$Query3<P>\n"); mysql_close ($Link); Thanks, Peace Link to comment https://forums.phpfreaks.com/topic/193286-include-mailer-within-phh-if-statements/ Share on other sites More sharing options...
jponte Posted February 26, 2010 Author Share Posted February 26, 2010 I was able to re-arrange and figure out the logic....Thanks Link to comment https://forums.phpfreaks.com/topic/193286-include-mailer-within-phh-if-statements/#findComment-1018712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.