ok, i'm not using the 'mail()' function built into php, i wrote a function that goes directly to the email server (whichever one you specify). does anyone have any idea how to attach a file? any help would be appreciated. thanks.

    here's kindof what it looks like:


    function eMail($toname, $toemail, $fromname, $fromemail, $subject, $body, $cc, $bcc) {
    $date = exec("date +'%Y-%m-%d %H:%M:%S'");
    //**************************
    // $tmpfile = $DOCUMENT_ROOT . "/tempemails/" . date('Y-m-d') . "" . $toname . "" . uniqid('');
    // exec("echo \"toname: " . $toname . "\" >> " . $tmpfile);
    // exec("echo \"toemail: " . $toemail . "\" >> " . $tmpfile);
    // exec("echo \"fromname: " . $fromname . "\" >> " . $tmpfile);
    // exec("echo \"fromemail: " . $fromemail . "\" >> " . $tmpfile);
    // exec("echo \"subject: " . $subject . "\" >> " . $tmpfile);
    // exec("echo \"cc: " . $cc . "\" >> " . $tmpfile);
    // exec("echo \"bcc: " . $bcc . "\" >> " . $tmpfile);
    // exec("echo \"body: " . $body . "\" >> " . $tmpfile);
    //
    ************************
    $subject = stripslashes($subject);
    $body = stripslashes($body);
    $toemail = fixCommaArray(str_replace(";", ",", $toemail));
    // echo("toemail: " . $toemail . "<br>");
    $cc = fixCommaArray(str_replace(";", ",", $cc));
    // echo("cc: " . $cc . "<br>");
    $bcc = fixCommaArray(str_replace(";", ",", $bcc));
    // echo("bcc: " . $bcc . "<br>");
    if(trim($alt_domain) != "") {
    $mailserver = $alt_domain;
    } else {
    $mailserver="mailserver.domain.com";
    }
    $smtp_sock = fsockopen($mailserver, 25, $errno, $errstr);
    if(!$smtp_sock) {
    // echo("ERROR!!!");
    $extra_errors = $extra_errors . "[fsockopen reported an error: " . $errno . " - " . $errstr . "; function: hhl_mail()]";
    $return = "false";
    } else {
    $errors = 0; // no errors from retrieving information from valid socket connection yet
    if(getInitialResponseFromSocket($smtp_sock, "220") != "true") {
    $errors++;
    }
    if(getResponseFromInputToSocket("helo " . $mailserver, $smtp_sock, "250") != "true") {
    $errors++;
    }
    if(getResponseFromInputToSocket("mail from: your_email@domain.com", $smtp_sock, "250") != "true") {
    $errors++;
    }
    $toarr = split(",", $toemail); // this and next few lines break up the 'to' by delimiting it with the comma (,); used for multiple recipients
    for($x = 0; $x < count($toarr); $x++) {
    if(getResponseFromInputToSocket("rcpt to: " . trim($toarr[$x]), $smtp_sock, "250") != "true") {
    $errors++;
    }
    }
    if(trim($cc) != "") {
    // append to the 'mailto' (rcpt to) field and populate the header to include 'cc'
    $ccarr = split(",", $cc);
    // echo("<font color='" . $specialcolor . "'>sending cc recipients</font><br>");
    for($y = 0; $y < count($ccarr); $y++) {
    // echo("<pre><hr>rcpt to: " . trim($ccarr[$y]) . "<hr></pre>");
    if(getResponseFromInputToSocket("rcpt to: " . trim($ccarr[$y]), $smtp_sock, "250") != "true") {
    $errors++;
    }
    }
    $cc = "
    Cc: " . $cc;

    }
    if(trim($bcc) != "") {
    // append to the 'mailto' (rcpt to) field and populate the header to include 'bcc'
    $bccarr = split(",", $bcc);
    // echo("<font color='" . $specialcolor . "'>sending bcc recipients</font><br>");
    for($z = 0; $z < count($bccarr); $z++) {
    // echo("<pre><hr>rcpt to: " . trim($bccarr[$z]) . "<hr></pre>");
    if(getResponseFromInputToSocket("rcpt to: " . trim($bccarr[$z]), $smtp_sock, "250") != "true") {
    $errors++;
    }
    }
    $bcc = "
    Bcc: " . $bcc;
    }
    if(getResponseFromInputToSocket("data", $smtp_sock, "354") != "true") {
    $errors++;
    }
    $datatosend = "Date: " . $date . "
    From: " . $fromname . " <" . $fromemail . ">
    To: " . $toemail . $cc . "
    Subject: " . $subject . "
    MIME-Version: 1.0
    Content-Type: text/html;
    Charset=\"iso-8859-1\"
    INSERT BODY HERE";
    // echo("<pre><hr>" . htmlentities($datatosend) . "<hr></pre>");
    if(getResponseFromInputToSocket($datatosend, $smtp_sock, "250") != "true") {
    $errors++;
    }
    if(getResponseFromInputToSocket("quit", $smtp_sock, "221") != "true") {
    $errors++;
    }
    }
    if($errors > 0) {
    $return = "false";
    } else {
    $return = "true";
    }
    return $return;

    }

    obviously i've made other functions that help get it out but this is the main part i'm dealing with - i need to be able to attach files but i've no clue how to insert it into the email as it goes out - how to upload it or anything...

      20 years later
      12 days later

      Welcome back! There might actually be some of us who've been here for 20 years. I know it's pretty close for me....

      6 days later

      dalecosp
      I was here circa 2005. I don't rem what my old UserID was (probably jsabarese), or it was abandoned or something...

      Nice to see y'all.

        Write a Reply...