Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007

    Unhappy Unanswered: sending mail with attachment

    I am trying to send mail with attachment and body part also . I am using following code it is working fine for attachment but not displaying body part.

    if($_FILES["fileatt"] != NULL)
    $fileatt_type = "application/octet-stream"; //File Type
    $email_from = ""; // Who the
    //email is from
    $email_subject = $_POST['sub']; // The Subject
    //of the email
    $email_txt = "Newsletter"; // Message that
    //the email has in it

    $email_to = ""; // Who the email is too

    $headers = "From:";

    $file = fopen($_FILES["fileatt"]["tmp_name"],"rb");

    $data =

    $semi_rand =(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";

    $email_message .= "This is a multi-partmessage in
    MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $email_message . "\n\n";

    $data = chunk_split(base64_encode($data));
    $email_message .= "--{$mime_boundary}\n" .
    "Content-Type: {$fileatt_type};\n" .
    " name=\"{$fileatt_name}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n" .
    $data . "\n" .
    $email_message = $email_message.$email_txt;
    echo $email_to;
    $ok = mail($email_to, $email_subject,$email_message,$headers);

    echo "<center><h4>The message has been sent sucessfully</h4></center>";
    die("Sorry but the email could not be sent.
    Please go back and try again!");
    <form name="mailfrm" action="attachment" method="post" enctype="multipart/form-data">
    <table cellpadding="0" cellspacing="1" border="0" width="50%" align="center">
    <th colspan="2" height="20">Send Mail to subscriber</th>

    <?php if($_REQUEST['mem']=='')
    { ?>
    <td align="right">Subscriber name :&nbsp;</td>
    <td><input type="text" name="subscriber" id="subscriber" value="<?php echo $FetchRec->fnam." ".$FetchRec->lnam;?>" size="40" readonly="true" tabindex="-1"/></td></tr>
    <?php } ?>

    <td align="right">Subject :&nbsp;</td>
    <td><input type="text" name="subject" id="subject" value="" size="40"></td>
    <td align="right">Attachment :&nbsp;</td>
    <td><input type="file" name="fileatt" value="" size="40"></td>
    <td align="right">Message :&nbsp;</td>
    <td><textarea name="msg" id="msg" rows="4" cols="50"></textarea></td>
    <td colspan="2" align="center" height="25"><input type="submit" name="sentmail" value="Send" onClick="return ValidateMail()">&nbsp;<input type="button" name="back" value="Back" onClick="location.href='newssublist.php'"></td>



  2. #2
    Join Date
    Mar 2007
    Having had a skim of the code ; Try taking the attachment out (along with the relevant headers for it) but leave the email as multipart and see if you can get the html to come through. I suspect your headers might be at fault, but unfortunately mail header are not my area of expertise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts