hi
i want to attach documents with the email.i have a field in my db which contains the path where the file is stored.when the user want a particular doc ....i want it to fetch from the database and send it to their email address..................

hi i want to know whether we can attach documents with php email feature.

hi, try something like this: (it works for me)

<?php
$to = 'youraddress@example.com';
$subject = 'Test email with attachment';

//create an unique boundary string.
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
?>
<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"

<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

This is text email message.

<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<?php echo $random_hash; ?>

<?php echo $random_hash; ?>
Content-Type: application/zip; name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php echo $attachment; ?>
<?php echo $random_hash; ?>

<?php
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

hi
all the path for a particular file is store in the db
.i want to know whether i can use the code for such fuction
$up contailns the path

<?php
$to = 'lydia.whitin@gmail.com';
$subject = 'Test email with attachment';

//create an unique boundary string.
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
// $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
$attachment = chunk_split(base64_encode(file_get_contents('$up')));
?>
<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"

<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
hi

<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<?php echo $random_hash; ?>

<?php echo $random_hash; ?>
// Content-Type: application/zip; name="attachment.zip"
Content-Type: application/doc; name="$up"

Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php echo $attachment; ?>
<?php echo $random_hash; ?>

<?php
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.