Force xml to open as excel

I am creating an XML file on a web server using php; technique is perfect. I save the file to a folder on the web server, then download it using ftp & open in Excel, works perfect.

The real intent is to run a chron job weekly at a predetermined time that will create the xml file & email it to recipients as an attachment. I am using the class phpmailer. It sends the email, with attachment correctly, but it cannot be opened using Excel (at least in Windows).

How can I force it to recognize that I want it opened in Excel without having each recipient have to screw with their own associations of extensions.

Here is my code for the mailing:

<?php
// send_urpt.php
function date_conv($x) {
 $r = substr($x,5,2) . "/" . substr($x,8,2) . "/" . substr($x,0,4);
 return $r;
}
session_start();
require_once('class.phpmailer.php');
$mail             = new PHPMailer(); // defaults to using php "mail()"

$mail->isSMTP(); // telling the class to use SMTP transport
 
$body             = "";
 
$mail->SetFrom('noreply@lakos.com');
$mail->SMTPSecure = $GLOBALS['smtp_security'];
$mail->Port       = $GLOBALS['smtp_port'];
$mail->AddReplyTo("lit@lakos.com", "replyto");
$body = "Attached is the usage report for the hvac configurator for the period " . date_conv($_SESSION['psat']) . " through 5PM Pacific Time on " . date_conv($_SESSION['currfri']) . ".";
$mail->MsgHTML($body);
$mail->AddAttachment($_SESSION['urpt']);
$mail->AddAddress("Prashant.Joshi@lakos.com");
$mail->AddAddress("richardkorts@gmail.com");
$mail->AddAddress("charis.calvert@lakos.com");
$mail->Subject   = "LAKOS hvac usage report";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
	//$loc = "Location: " . $back . "?em=Y"
	echo "Mail successfully sent.";
	exit;
	//echo $loc;
}	
?>

Open in new window


Thanks
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Change the extension to .xls

Even though it is XML Excel should open it. It will prompt you with a message box but the file should open.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jan Karel PieterseExcel and VBA ExpertCommented:
Even though changing the files extension to xls may solve the issue of opening in Excel I am no fan of faking it by changing extensions. I wouldn't be surprised if a day comes where security settings will prevent the system from opening the files at all as their extension does not match the filetype.
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Works good.

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.