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 KortsAsked:
Who is Participating?
 
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
 
jkpieterseCommented:
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 KortsAuthor Commented:
Works good.

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.