How to send Excel for PHP export as a message
Now the implementation of the click after the download of Excel, and send text messages, how can be combined, the PHP exported Excel as an attachment to send the perfect.
1. Generate Excel:
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename=". $filename. ". XLS ");
Header ("Pragma:no-cache");
Header ("expires:0");
if (!empty ($title)) {
foreach ($title as $k = = $v) {
$title [$k]=iconv ("UTF-8", "GB2312", $v);
}
$title = implode ("\ T", $title);
echo "$title \ n";
}
if (!empty ($data)) {
foreach ($data as $key = = $val) {
foreach ($val as $ck = = $CV) {
$data [$key] [$ck]=iconv ("UTF-8", "GB2312", $CV);
}
$data [$key]=implode ("\ t", $data [$key]);
}
echo implode ("\ n", $data);
}
2. To send a message:
Using the Phpmailer class library
$mail = new Phpmailer ();
$mail->charset = ' UTF-8 ';
$mail->issmtp ();
$mail->smtpauth = true;
$mail->smtpsecure = ";
$mail->host = $config [' Smtp_host ']; SMTP Server
$mail->port = $config [' Smtp_port ']; Port number of the SMTP server
$mail->username = $config [' Smtp_user ']; SMTP Server user name
$mail->password = $config [' Smtp_pass ']; SMTP server password
$mail->setfrom ($config [' From_email '], $config [' from_name ']);
$replyEmail = $config [' Reply_email ']? $config [' Reply_email ']: $config [' from_email '];
$replyName = $config [' Reply_name ']? $config [' Reply_name ']: $config [' from_name '];
$mail->addreplyto ($replyEmail, $replyName);
$mail->subject = $subject;
$mail->msghtml ($body);
$mail->addaddress ($to, $name);
if (Is_file ($attachment)) {//Add attachment
$mail->addattachment ($attachment);
}
return $mail->send ()
------Solution--------------------
Join at Line 7th
Ob_start ();
Add after line 23rd
$s = Ob_get_flush ();
File_put_contents ($filename. ". XLS ", $s);
$attachment = $filename. ". XLS ";
Performing a Mail send
------Solution--------------------
There must be something wrong with you, check it carefully.
You actually output a text file, you can open it with Notepad
The functions and usages of OB functions are available in the manual.
------Solution--------------------
How do you send it as an attachment if you don't have a path for that export??
Don't you think it's a fantasy?
------Solution--------------------
To make a thought, you can refer to the following:
Save Excel on the server first, then get the Excel path, and then as an attachment to send an email, if you do not need this file, and then perform the delete operation is OK
http://www.bkjia.com/PHPjc/820422.html www.bkjia.com true http://www.bkjia.com/PHPjc/820422.html techarticle How to send PHP exported Excel as a mail now realize the click to download Excel, and send text message function, how can combine, the PHP exported Excel as an attachment to send the end ...