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:

// send_urpt.php
function date_conv($x) {
 $r = substr($x,5,2) . "/" . substr($x,8,2) . "/" . substr($x,0,4);
 return $r;
$mail             = new PHPMailer(); // defaults to using php "mail()"

$mail->isSMTP(); // telling the class to use SMTP transport
$body             = "";
$mail->SMTPSecure = $GLOBALS['smtp_security'];
$mail->Port       = $GLOBALS['smtp_port'];
$mail->AddReplyTo("", "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->Subject   = "LAKOS hvac usage report";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
	//$loc = "Location: " . $back . "?em=Y"
	echo "Mail successfully sent.";
	//echo $loc;

Open in new window

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.
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.
Richard KortsAuthor Commented:
Works good.

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.