Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP mailing script to include dynamic data from an includes file Need Help

Posted on 2013-05-29
8
Medium Priority
?
374 Views
Last Modified: 2013-05-31
Hi

I have a mailing script which I need to use to send data from a database out in a specific format. I know the .php file which gets this data is working correctly but when I try to include it in the mailing script only static data is sent from the file none of the database data is sent. The mailing script is activated via an ajax function which is working correctly.

Any help would be much appreciated

Cheers Neil

<?php

$to_email = "me@test.com";
$email_subject = "RIDDOR Notification";
$email_content = "Riddor XML:\n";
$from = "support@sevron.co.uk";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $from";

//$email_data = file_get_contents('riddor-mailinglist.php');

ob_start();
//echo $email_data;

include "riddor-mailinglist.php";

$email_content = ob_get_contents();


if (mail($to_email, $email_subject, $email_content, $headers)) {
    ob_end_clean();
    echo '<p style="text-align:center;padding:20px;padding-top:40px;font-family:Arial;font-size:12px;">Message has been sent.<br/><br/>';
}

//else {
//    echo 'ERROR - message not sent. <br/><br/>';
//}
?> 

Open in new window

0
Comment
Question by:Sevron
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39204752
Place your mysql connection info directly in riddor-mailinglist.php and see if that helps.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39204754
Let's try to reduce this to the SSCCE.  What happens in the include statement on line 16?  Is that where the data is acquired from the database?
0
 

Author Comment

by:Sevron
ID: 39205004
Hi Thank you both for the quick replies The connection to the database is within the mailing list file (well the config file with the connection into in) and the file has the code on it to gather the data from the database yes. I have added the code from the riddor-mailinglist.php file below (this file has to output the data in an as XML). When I access this file directly the data is being brought back.

<?php

session_start();

include("../../../res/includes/config.php");

$link = sqlsrv_connect($sName, $cInfo);

if ($link == false) {
    echo "Could not connect.\n";
    die(print_r(sqlsrv_errors(), true));
}


    $pkRiddorID = $_SESSION['pkRiddorID'];

//echo $_SESSION['pkRiddorID];
//stored procedure used to gather the data from the DB
$sql = "EXEC SP_v3_incident_riddor_mailinglist_web @pkRiddorID=?";
//parameter used to find the data 
$params = array(
    array($pkRiddorID, SQLSRV_PARAM_IN)
);

/* Execute the query. */
$stmt = sqlsrv_query($link, $sql, $params);

if ($stmt === false) {
    echo "Error in executing statement. SP_v3_ims_incident_riddor_mailinglist_web\n";
    die(print_r(sqlsrv_errors(), true));
}

if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) {
    header("Content-type: application/xhtml+xml");
} else {
    header("Content-type: text/xml");
}
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");

$output = "<injuries xmlns='urn:HSE_Namespace' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='urn:HSE_Namespace HSESchemaFile.xsd' >";

$loopcount = 1;

$row = sqlsrv_fetch_array($stmt);

    $output .= "<injury>";
//        $output .= "<count id='" . $loopcount . "'></count>"; //will probably need removing unsure at this point keep for my benefits
        $output .= "<customer_ref><![CDATA[". $row['fkIncidentID']. rand(1, 99) . "]]></customer_ref>";
        $output .= "  <notification_type>F2508IE</notification_type>";
        $output .="<notifier>";
            $output .= "<Title><![CDATA[" . $row['Title'] . "]]></Title>";
            $output .= "<Forename><![CDATA[" . $row['FirstName'] . "]]></Forename>";
            $output .= "<Familyname><![CDATA[" . $row['LastName'] . "]]></Familyname>";
            $output .= "<Jobtitle><![CDATA[" . $row['JobTitle'] . "]]></Jobtitle>";
            $output .= "<Phonenumber><![CDATA[" . $row['Phone'] . "]]></Phonenumber>";
            $output .= "<org_name><![CDATA[" . $row['OrganisationName'] . "]]></org_name>";
            $output .= "<org_addressline1><![CDATA["."org_" . $row['Address1'] . "]]></org_addressline1>";
            $output .= "<org_addressline2><![CDATA["."org_" . $row['Address2'] . "]]></org_addressline2>";
            $output .= "<org_addressline3><![CDATA["."org_" . $row['Address3'] . "]]></org_addressline3>";
            $output .= "<org_town><![CDATA["."org_" . $row['Town'] . "]]></org_town>";
            $output .= "<org_county><![CDATA["."org_" . $row['County'] . "]]></org_county>";
            $output .= "<org_postcode><![CDATA[" ."org_". $row['PostCode'] . "]]></org_postcode>";
            $output .= "<org_faxnumber><![CDATA[" . $row['Fax'] . "]]></org_faxnumber>";
            $output .= "<Email><![CDATA[" . $row['Email'] . "]]></Email>";
        $output .= "</notifier>";

if($row['WhereIncident'] == 1){

        $output .= "<incident_location>";
            $output .= "<Location><![CDATA[" . $row['WhereIncident'] . "]]></Location>";
            $output .= "<authority_responsible><![CDATA[" . $row['ResponsibleAuthority'] . "]]></authority_responsible>";
/*            $output .= "<loc_addressline1><![CDATA[" . $row['WhereAddress1'] . "]]></loc_addressline1>";
            $output .= "<loc_addressline2><![CDATA[" . $row['WhereAddress2'] . "]]></loc_addressline2>";
            $output .= "<loc_addressline3><![CDATA[" . $row['WhereAddress3'] . "]]></loc_addressline3>";
            $output .= "<loc_town><![CDATA[" . $row['WhereTown'] . "]]></loc_town>";
            $output .= "<loc_county><![CDATA[" . $row['WhereCounty'] . "]]></loc_county>";
            $output .= "<loc_postcode><![CDATA[" . $row['WherePostCode'] . "]]></loc_postcode>";*/
            $output .= "<loc_description><![CDATA[" . $row['WhereDetails'] . "]]></loc_description>";
        $output .= "</incident_location>";
}else{
    $output .= "<incident_location>";
    $output .= "<Location><![CDATA[" . $row['WhereIncident'] . "]]></Location>";
    $output .= "<authority_responsible><![CDATA["  . $row['ResponsibleAuthority'] . "]]></authority_responsible>";
    $output .= "<loc_addressline1><![CDATA["."loc_" . $row['WhereAddress1'] . "]]></loc_addressline1>";
    $output .= "<loc_addressline2><![CDATA["."loc_" . $row['WhereAddress2'] . "]]></loc_addressline2>";
    $output .= "<loc_addressline3><![CDATA["."loc_" . $row['WhereAddress3'] . "]]></loc_addressline3>";
    $output .= "<loc_town><![CDATA["."loc_" . $row['WhereTown'] . "]]></loc_town>";
    $output .= "<loc_county><![CDATA["."loc_" . $row['WhereCounty'] . "]]></loc_county>";
    $output .= "<loc_postcode><![CDATA["."loc_" . $row['WherePostCode'] . "]]></loc_postcode>";
    $output .= "<loc_description><![CDATA[" . $row['WhereDetails'] . "]]></loc_description>";
    $output .= "</incident_location>";
}

        $output .="<incident>";
            $output .= "<Date><![CDATA[" . $row['IncidentDate'] . "]]></Date>";
            $output .= "<Time><![CDATA[" . $row['IncidentTime'] . "]]></Time>";
            $output .= "<local_authority><![CDATA[" . $row['LocalAuthority'] . "]]></local_authority>";
            $output .= "<Department><![CDATA[" . $row['IncidentDepartment'] . "]]></Department>";
            $output .= "<sub_activity><![CDATA[" . $row['SubActivity'] . "]]></sub_activity>";
            $output .= "<incident_kind><![CDATA[" . $row['KindAccident'] . "]]></incident_kind>";
            $output .= "<Fallheight><![CDATA[" . $row['FallHeight'] . "]]></Fallheight>";
            $output .= "<workprocessinvolved><![CDATA[" . $row['WorkProcess'] . "]]></workprocessinvolved>";
            $output .= "<main_factor_involved><![CDATA[" . $row['MainFactor'] . "]]></main_factor_involved>";
            $output .= "<what_happened_description><![CDATA[" . $row['WhatHappened'] . "]]></what_happened_description>";
        $output .="</incident>";

        $output .="<injured_person>";
            $output .= "<ip_nametitle><![CDATA["."ip_". $row['IPTitle'] . "]]></ip_nametitle>";
            $output .= "<ip_givename><![CDATA["."ip_" . $row['IPFirstName'] . "]]></ip_givename>";
            $output .= "<ip_familyname><![CDATA["."ip_" . $row['IPLastName'] . "]]></ip_familyname>";
            $output .= "<ip_addressline1><![CDATA["."ip_" . $row['IPAddress1'] . "]]></ip_addressline1>";
            $output .= "<ip_addressline2><![CDATA["."ip_". $row['IPAddress2'] . "]]></ip_addressline2>";
            $output .= "<ip_addressline3><![CDATA[" ."ip_". $row['IPAddress3'] . "]]></ip_addressline3>";
            $output .= "<ip_town><![CDATA[" ."ip_". $row['IPTown'] . "]]></ip_town>";
            $output .= "<ip_county><![CDATA[" ."ip_". $row['IPCounty'] . "]]></ip_county>";
            $output .= "<ip_postcode><![CDATA["."ip_" . $row['IPPostCode'] . "]]></ip_postcode>";
            $output .= "<ip_telephonenumber><![CDATA[" . $row['IPPhone'] . "]]></ip_telephonenumber>";
            $output .= "<ip_gender><![CDATA[" . $row['IPGender'] . "]]></ip_gender>";
            $output .= "<ip_age><![CDATA[" . $row['IPAge'] . "]]></ip_age>";
            $output .= "<ip_jobtitle><![CDATA[" . $row['IPOccupation'] . "]]></ip_jobtitle>";
            $output .= "<ip_employment_status><![CDATA[" . $row['IPStatus'] . "]]></ip_employment_status>";
            $output .= "<ip_status_description><![CDATA[" . $row['IPStatusDetails'] . "]]></ip_status_description>";
        $output .="</injured_person>";

        $output .="<injured_person_injuries>";
            $output .= "<ip_injurysustained><![CDATA[" . $row['IPInjury'] . "]]></ip_injurysustained>";
            $output .= "<ip_partofbodyinjured><![CDATA[" . $row['IPInjuryLocation'] . "]]></ip_partofbodyinjured>";
            $output .= "<ip_unconsciuos><![CDATA[" . $row['IPUnconscious'] . "]]></ip_unconsciuos>";
            $output .= "<ip_resuscitation><![CDATA[" . $row['IPResuscitated'] . "]]></ip_resuscitation>";
            $output .= "<ip_hospitalised><![CDATA[" . $row['IPHospital'] . "]]></ip_hospitalised>";
            $output .= "<ip_severity><![CDATA[" . $row['IPInjurySeverity'] . "]]></ip_severity>";
        $output .="</injured_person_injuries>";


    $output .= "</injury>";
   //$output .= "";



//$output .="</injuries>";
$output .="</injuries>";

echo $output;
?>

Open in new window


Thanks again Neil
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39205121
Being your code is not returning data try putting the absolute path in for the following:


include("../../../res/includes/config.php");

IE: include ("/home/username/public_html/res/includes/config.php");

Or for a test place the content of config.php in your php file and comment out your include.
0
 

Author Comment

by:Sevron
ID: 39205146
Hi Again

I placed the database connection directly onto the mailinglist page unfortunately I got the same result the static data was sent but none of the dynamic .
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 39206268
Please add this line to the top of all of your PHP scripts (at this point in the application lifecycle you really want to see all of the error information):

error_reporting(E_ALL);

Change line 9 from this:

if ($link == false) {

To this:

if ($link === false) {

Change line 11 from this:

die(print_r(sqlsrv_errors(), true));

To this (and make similar changes where there are other tests for errors):

$x = sqlsrv_errors();
trigger_error($x, E_USER_ERROR);

After line 44, add this:

var_dump($row);

Armed with this information you may be better equipped to see what is going on with the script and how it is operating on the data.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39210419
@it-wizard: I see you are new to EE and so you may not have yet read the grading guidelines.  It's not like grammar school.  Giving a grade less than "A" without question or explanation is unacceptable in this community.
http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26

If there was something wrong or inadequate in the answers you received, you can and should engage in dialog with the community so that we can, together, run the problem to ground.
0
 

Author Comment

by:Sevron
ID: 39210537
Hi I am new yes the answer helped guide me towards the answer. It was an issue in the mailing list file with the way I had declared the variables because our live server is really ify with variables which are not within an ISSET statement.

So your answer didn't give me the solution but I felt you should be given pionts as you tried to help me which counts for alot.

I didn't read the awards info before I gave the points out so sorry about that I understand the system now.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question