• Hy there

    Is there a specific setting needed to send attachments?
    Though email goes through, Whatever attachments I send get reduced to 0 bytes.
    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter eaacaadmin

    (@eaacaadmin)

    This is what I found online

    $headers = “MIME-Version: 1.0\r\n”;
    $headers .= “To: <“.$to_email.”>\r\n”;
    $headers .= “From: “.$from_name.” <“.$from_email.”>”;
    $random_hash = md5(date(‘r’, time()));
    // add boundary string and mime type specification
    $headers .= “\r\nContent-Type: multipart/mixed; boundary=\”PHP-mixed-“.$random_hash.”\””;
    // read the atachment file contents from a string previously formed,
    // encode it with MIME base64,
    // and split it into smaller chunks
    $attachment = chunk_split(base64_encode($content));
    // construct the body of the message
    $message = “–PHP-mixed-“.$random_hash;
    // my attachment was an html file
    $message .= “\r\nContent-Type: text/html; name=\””.$filename.”\””;
    $message .= “\r\nContent-Transfer-Encoding: base64”;
    $message .= “\r\nContent-Disposition: attachment\r\n”.$attachment.”\r\n”;
    $message .= “\r\n–PHP-mixed-“.$random_hash.”–“;
    // Windows
    ini_set(‘sendmail_from’, $return_email);
    mail($to_email, addslashes($subject), $message, $headers);
    ini_restore(‘sendmail_from’);
    // Linux
    // mail($to_email, addslashes($subject), $message, $headers, “-r “.$return_email);

    Thread Starter eaacaadmin

    (@eaacaadmin)

    with another message

    I received an email with an attachment, but the problem was that the attached file had 0 bytes.
    To my surprise, after comparing the source of the email with the source of an email with a complete attachment, I found out the problem: before the actual content of the attachment ($attachment) there should be an empty line.
    I replaced the line of code:

    $message .= “\r\nContent-Disposition: attachment\r\n”.$attachment.”\r\n”;

    with:
    ?
    1

    $message .= “\r\nContent-Disposition: attachment\r\n\r\n”.$attachment.”\r\n”; // notice the double \r\n

    and it worked! This way I received the email with the correct attachment.

    Thread Starter eaacaadmin

    (@eaacaadmin)

    Finally

    Does smtp plugin support sending attachments?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Email attachment not being sent’ is closed to new replies.