Sevron
asked on
PHP mailing script to include dynamic data from an includes file Need Help
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
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/>';
//}
?>
Place your mysql connection info directly in riddor-mailinglist.php and see if that helps.
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?
ASKER
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.
Thanks again Neil
<?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;
?>
Thanks again Neil
Being your code is not returning data try putting the absolute path in for the following:
include("../../../res/incl udes/confi g.php");
IE: include ("/home/username/public_ht ml/res/inc ludes/conf ig.php");
Or for a test place the content of config.php in your php file and comment out your include.
include("../../../res/incl
IE: include ("/home/username/public_ht
Or for a test place the content of config.php in your php file and comment out your include.
ASKER
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 .
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 .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@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.
https://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.
https://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.
ASKER
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.
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.