I have a strange issue, i have a doc file on the server with the following text in:
Thank u....
I am using the following to attach the document to my mail: - <!-- Mail Attachment -->
-
<?php
-
if(isset($_POST['sub']))
-
{
-
//define the receiver of the email
-
$to = $_POST['mailid'];
-
//define the subject of the email
-
$subject = 'Test email with attachment';
-
//create a boundary string. It must be unique
-
//so we use the MD5 algorithm to generate a random hash
-
$random_hash = md5(date('r', time()));
-
//define the headers we want passed. Note that they are separated with \r\n
-
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
-
//add boundary string and mime type specification
-
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
-
//read the atachment file contents into a string,
-
//encode it with MIME base64,
-
//and split it into smaller chunks
-
//$attachments=file_get_contents('/var/chroot/home/content/67/7399467/html/confirmation.zip');
-
$attachment = chunk_split(base64_encode(file_get_contents('/var/chroot/home/content/67/7399467/html/confirmation.zip')));
-
echo $attachments;
-
//define the body of the message.
-
ob_start(); //Turn on output buffering
-
?>
-
--PHP-mixed-<?php echo $random_hash; ?>
-
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
-
--PHP-alt-<?php echo $random_hash; ?>
-
Content-Type: text/plain; charset="iso-8859-1"
-
Content-Transfer-Encoding: 7bit
-
Hello World!!!
-
This is simple text email message.
-
-
--PHP-alt-<?php echo $random_hash; ?>
-
Content-Type: text/html; charset="iso-8859-1"
-
Content-Transfer-Encoding: 7bit
-
<h2>Hello World!</h2>
-
<p>This is something with <b>HTML</b> formatting.</p>
-
-
--PHP-alt-<?php echo $random_hash; ?>--
-
--PHP-mixed-<?php echo $random_hash; ?>
-
Content-Type: application/zip; name="attachment.zip"
-
Content-Transfer-Encoding: base64
-
Content-Disposition: attachment
-
<?php echo $attachment; ?>
-
--PHP-mixed-<?php echo $random_hash; ?>--
-
-
<?php
-
//copy current buffer contents into $message variable and delete current output buffer
-
$message = ob_get_clean();
-
//send the email
-
$mail_sent = @mail( $to, $subject, $message, $headers );
-
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
-
echo $mail_sent ? "Mail sent" : "Mail failed";
-
}
-
?>
When i try to echo $attachments.i get the strange characters in my output screen.I did so,because my mail is
sending with no attachment and text(nomane 0k as attachment file) and no text in body.
I myself solved the issue.This might help others. - $to = $_POST['mailid'];
-
$from = "VySystems <vijaya@vysystems.com>";
-
$subject = $_POST['uname']."testing";
-
-
$separator = md5(time());
-
-
// carriage return type (we use a PHP end of line constant)
-
$eol = PHP_EOL;
-
-
// attachment name
-
$filename = "ip.zip";
-
-
//$pdfdoc is PDF generated by FPDF
-
$attachment = chunk_split(base64_encode(file_get_contents('ip.zip')));
-
-
// main header
-
$headers = "From: ".$from.$eol;
-
$headers .= "MIME-Version: 1.0".$eol;
-
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
-
-
// no more headers after this, we start the body! //
-
-
$body = "--".$separator.$eol;
-
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
-
$body .= "This is a MIME encoded message.".$eol;
-
-
// message
-
$body .= "--".$separator.$eol;
-
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
-
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
-
$body .= $message.$eol;
-
-
// attachment
-
$body .= "--".$separator.$eol;
-
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
-
$body .= "Content-Transfer-Encoding: base64".$eol;
-
$body .= "Content-Disposition: attachment".$eol.$eol;
-
$body .= $attachment.$eol;
-
$body .= "--".$separator."--";
-
-
// send message
-
if (mail($to, $subject, $body, $headers)) {
-
echo "mail send ... OK";
-
} else {
-
echo "mail send ... ERROR";
-
}
1 2446
I myself solved the issue.This might help others. - $to = $_POST['mailid'];
-
$from = "VySystems <vijaya@vysystems.com>";
-
$subject = $_POST['uname']."testing";
-
-
$separator = md5(time());
-
-
// carriage return type (we use a PHP end of line constant)
-
$eol = PHP_EOL;
-
-
// attachment name
-
$filename = "ip.zip";
-
-
//$pdfdoc is PDF generated by FPDF
-
$attachment = chunk_split(base64_encode(file_get_contents('ip.zip')));
-
-
// main header
-
$headers = "From: ".$from.$eol;
-
$headers .= "MIME-Version: 1.0".$eol;
-
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
-
-
// no more headers after this, we start the body! //
-
-
$body = "--".$separator.$eol;
-
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
-
$body .= "This is a MIME encoded message.".$eol;
-
-
// message
-
$body .= "--".$separator.$eol;
-
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
-
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
-
$body .= $message.$eol;
-
-
// attachment
-
$body .= "--".$separator.$eol;
-
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
-
$body .= "Content-Transfer-Encoding: base64".$eol;
-
$body .= "Content-Disposition: attachment".$eol.$eol;
-
$body .= $attachment.$eol;
-
$body .= "--".$separator."--";
-
-
// send message
-
if (mail($to, $subject, $body, $headers)) {
-
echo "mail send ... OK";
-
} else {
-
echo "mail send ... ERROR";
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Buck Turgidson |
last post by:
Not sure if this is a php or Apache2 question, but I get strange characters
when using phpman to generate linux man pages, as shown below. Using
another server, I don't have the problem. Could...
|
by: Roman Muntyanu |
last post by:
Hi all !
After I run resgen my.fr-CA.txt my.fr-CA.resx
I got my.fr-CA.resx without any french characters, they were cut at all.
How to let resgen know about language specific encoding ?
...
|
by: Amaryllis |
last post by:
I'm trying to call a CL which is located on our AS400 from a Windows
application. I've tried to code it in different ways, but I seem to
get the same error every time. Does anyone have any clue...
|
by: Richard Marsden |
last post by:
Here's another strange error I'm getting when using ODBC to access
MySQL. This time ODBC is being more informative, although all the
documentation I've looked at, claims that the function in...
|
by: laredotornado |
last post by:
Hi,
Using PHP 4, I'm trying to create a class, and I get warnings in my
constructor function like the one below:
Notice: Undefined variable: m_cat_to_buy in...
|
by: John Salerno |
last post by:
If I read a string that contains a newline character(s) into a variable,
then write that variable to a file, how can I retain those newline
characters so that the string remains on one line rather...
|
by: Curtis |
last post by:
Hello everyone:
I have come to love the ease of updating PHP, since getting used to
using it these past few years. Recently, however, when I upgraded from
PHP 5.1 to PHP 5.2.0 and again when...
|
by: Sinister747 |
last post by:
Hi All,
I am using FCKEditor to allow a client to input a news article.. and the output is saved in MS Access.
However when i output the record i get a "Â" character randomly positioned in the...
|
by: danalovesc |
last post by:
Hi all, i'm new to Templates and when i tried to implement templates methods which needs to use a map (which is a member in private), the map can only do 3 things: insert, swap, and operator =. and i...
|
by: adamjblakey |
last post by:
Hi,
I have a strange issue, i have a txt file on the server with the following text in:
In what ways has 'time-space compression' transformed geographies of consumption and production?
I am...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |