If geeks love it, we’re on it

Howdy, Stranger!

You found the friendliest gaming & tech geeks around. Say hello!

PHP email form with attachments?

1234689

Comments

  • IvanIvan Icrontic’s Loveable Bot
  • jakekohjakekoh Member
    Hi,
    anyone? i tried this on my server but the attachment i tried to send with my form mail does not comes in base64 which should turn out to be a file instead of a string of codes inside the mail.
    thanks everyone in advance.


    <?php
    $email = $_REQUEST['email'];
    $message = $_REQUEST['message'];
    $msg = $_REQUEST['msg'];
    $subject = $_REQUEST['subject'];
    $coname = $_REQUEST['coname'];
    $user = $_REQUEST['user'];
    $reg = $_REQUEST['reg'];
    $ctc = $_REQUEST['ctc'];
    $xbrldoc = $_REQUEST['xbrldoc'];
    $doc = $_REQUEST['doc'];
    $ver = $_REQUEST['ver'];
    $dnt = $_REQUEST['dnt'];
    $agent = $_REQUEST['agent'];
    $attachment = $_FILES['attachment']['tmp_name'];
    $attachment_name = $_FILES['attachment']['name'];
    if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $fp = fopen($attachment, \"rb\"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    }
    mail( \"to@mail.com\", \"$subject\", \"Hi Daniel, \n\nProblem Description: $msg \n\n\n\nUser's Name: $user \nCo Regn No: $reg \nCompany Name: $coname \nContact No: $ctc \nEmail Address: \n\n\nXBRL Document: $xbrldoc \nText Source Document: $doc \nWeb Browser Version: $ver \nDate/Time Error occured: $dnt \n\n\n\n\nRegards,\n$agent \nHelpdesk \n$data\", \"From: me@mail.com\");
    header( \"Location: thankyou.htm\" );
    ?>
  • Hey guys,

    I was wondering if someone could help me out.

    Using the script provided (1st page), I am able to send emails with attachments and I get the email and attachment intact. However, no body (no message!) shows up on webmail OR Pop3 when I check it.

    This is stock script with minimal modifications. Has anyone experienced this?.. or know of a work-around?
  • jakekohjakekoh Member
    maybe you want to paste your code here?
  • Like I said, its pretty stock. After grabbing it and modifying it didnt work... I kept deleting my modifactions all the way back until I have damn nearly the exact file I pulled from the post on page 1. I upload it, populate, send, it works and sends emails just no body-text output at all.

    Basically, just a static from and a static to email address. Being used as a basic contact form with resume attachment.

    Noticed a couple other people had the same problem earlier on in the thread but never seemed to have gotten a reply.

    [html]



    PHP Code:
    <?php</font>
    /* Mailer with Attachments */
    $action = $_REQUEST['action'];
    global $action;
    function showForm() {
    ?>
    " method=post encType=multipart/form-data>



    Name:
    Email:
    Subject:
    Message:
    Attachment:



    <?php</font>
    }
    function sendMail() {
    $to_name = "";
    $from_name = stripslashes($_POST['name']);
    $subject = stripslashes($_POST['subject']);
    $body = stripslashes($_POST['body']);
    $to_email = "williamschott@comcast.net";
    $from_email = stripslashes($_POST['from_email']);
    $phone = stripslashes($_POST['phone']);
    //Let's start our headers
    $headers = "From: $from_name <" . $_POST['from_email'] . ">\n";
    $headers .= "Reply-To: <" . $_POST['from_email'] . ">\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
    $headers .= "X-Sender: $from_name <" . $_POST['from_email'] . ">\n";
    $headers .= "X-Mailer: PHP4\n";
    $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
    $headers .= "Return-Path: <" . $_POST['from_email'] . ">\n";
    $headers .= "This is a multi-part message in MIME format.\n";
    $headers .= "------=MIME_BOUNDRY_main_message \n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
    $message = "------=MIME_BOUNDRY_message_parts\n";
    $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: quoted-printable\n";
    $message .= "\n";
    $message .= "$body\n";
    $message .= "\n";
    $message .= "------=MIME_BOUNDRY_message_parts--\n";
    $message .= "\n";
    foreach($_FILES as $file => $value) {
    $_tmpname = $_FILES[$file]['tmp_name'];
    $_filename = $_FILES[$file]['name'];
    if (is_uploaded_file($_tmpname)) { //Do we have a file uploaded?
    $fp = fopen($_tmpname, "rb"); //Open it
    $data = fread($fp, filesize($_tmpname)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    $message .= "------=MIME_BOUNDRY_main_message\n";
    $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $_filename . "\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $_filename . "\"\n\n";
    $message .= $data; //The base64 encoded message
    $message .= "\n\n";
    fclose($fp);
    }
    }

    $message .= "------=MIME_BOUNDRY_main_message--\n";

    // send the message

    $ok = mail("$to_name <$to_email>", $subject, $body, $headers);

    if ($ok == 1) {
    print "Mail sent to $to_name ($to_email).";
    } else {
    print "Mail did not send. Please press the back button and re-submit the e-mail.";
    }
    }

    ?>


    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">








    <?php</font>
    switch ($action) {
    case "send":
    sendMail();
    showForm();
    break;
    default:
    showForm();
    }
    ?>








    [/html]
  • jakekohjakekoh Member
    did you name the textfield as 'body'?
  • hi Drenkhahn, did u get your attacment work or not?
    cause i m also using same, but nothing for the attacment
    can u explain?
    tks
  • Attachment works for me and always works for me.
  • So you do receive the email, but there's nothing in the body? Does the subject show?

    Paste the code you're using inside [ php ] [ /php ] tags (don't have the spaces)
  • a2jfreak said:
    So you do receive the email, but there's nothing in the body? Does the subject show?

    Paste the code you're using inside [ php ] [ /php ] tags (don't have the spaces)

    Its odd. Tested using outlook 2003 AND webmail. Problem is the same, regarless.

    I installed the same script on two remote hosting sites. My godaddy hosting runs it perfectly. The other no-name fischer-price webhost is the one I have the problems with, so I am sure its not the script's fault. The email from the problematic host shows a working attachment, but no message is displayed.

    So I've given up on it. Unless you know a work around.
    Similarly, I'll end up remote hosting the script and cross linking to it. But i need to work out a redirect to get me back to the origonal site after the script runs.


    header( "Location: [EMAIL="back@mysiteafterscriptruns.com"]back@mysiteafterscriptruns.com[/EMAIL]" );

    craps out.

    BTW, Im running Kwitko's script pretty much stock (shown partially above). Again, I'm fing out now I think the hosting is just cheap. Script is verified worker elsehwere for me.
  • jakekohjakekoh Member
    Drenkhahn, not so sure about you but i seperated my process into 2 parts. one the form in html the other the processing in php as below.

    form in html:
    [html]

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


    Form2Mail
    ****** http-equiv="Content-Type" content="text/html; charset=iso-8859-1">









    Name
    Email address
    Message
    Attachment
     





    [/html]

    here goes the php:

    <?php //information processed from form submitted.
    $msg = $_REQUEST['message'];
    $email = $_REQUEST['emailaddr'];$name = $_REQUEST['name'];
    $attachment = $_FILES['attachment']['tmp_name'];
    $attachment_name = $_FILES['attachment']['name'];
    if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $fp = fopen($attachment, \"rb\"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    } //Let's start our headers
    $headers = \"From: $email\n\";
    $headers .= \"Reply-To: $email\n\";
    $headers .= \"MIME-Version: 1.0\n\";
    $headers .= \"Content-Type: multipart/related; type=\\"multipart/alternative\\"; boundary=\\"----=MIME_BOUNDRY_main_message\\"\n\";
    $headers .= \"X-Sender: $name<\" . $_POST['email'] . \">\n\";
    $headers .= \"X-Mailer: PHP4\n\";
    $headers .= \"X-Priority: 3\n\"; //1 = Urgent, 3 = Normal
    $headers .= \"Return-Path: <\" . $_POST['email'] . \">\n\";
    $headers .= \"This is a multi-part message in MIME format.\n\";
    $headers .= \"------=MIME_BOUNDRY_main_message \n\";
    $headers .= \"Content-Type: multipart/alternative; boundary=\\"----=MIME_BOUNDRY_message_parts\\"\n\"; $message = \"------=MIME_BOUNDRY_message_parts\n\";
    $message .= \"Content-Type: text/plain; charset=\\"iso-8859-1\\"\n\";
    $message .= \"Content-Transfer-Encoding: quoted-printable\n\";
    $message .= \"\n\";
    //* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
    $message .= \"$msg\n\";
    $message .= \"\n\";
    $message .= \"------=MIME_BOUNDRY_message_parts--\n\";
    $message .= \"\n\";
    $message .= \"------=MIME_BOUNDRY_main_message\n\";
    $message .= \"Content-Type: application/octet-stream;\n\tname=\\"\" . $attachment_name . \"\\"\n\";
    $message .= \"Content-Transfer-Encoding: base64\n\";
    $message .= \"Content-Disposition: attachment;\n\tfilename=\\"\" . $attachment_name . \"\\"\n\n\";
    $message .= $data; //The base64 encoded message
    $message .= \"\n\";
    $message .= \"------=MIME_BOUNDRY_main_message--\n\"; //final code to send the message
    mail(\"mymail@my.com\", \"mailtoform\", $message, $headers);
    //the redirection page.
    header(\"Location: maildone.php\");
    ?>
  • Yes, of course. I have recently done so as well.

    Uploaded to my site, the script runs perfectly. Uploaded to client's site, the email craps out and arrives w/ attachment and no message.

    So I know the code is correct.
  • xysaxysa Member
    hello....mr [B]Kwitko can you pls help me..ur code works very fine..but i need to attach multiple files....and i try to use foreach...but i cant get the right one..am lost...could u pls show me the code..pls?tnx
    [/B]
  • xysa said:
    hello....mr [B]Kwitko can you pls help me..ur code works very fine..but i need to attach multiple files....and i try to use foreach...but i cant get the right one..am lost...could u pls show me the code..pls?tnx
    [/B]
    That functionality was added some time back. Look through this thread again and you'll see the code for it.
  • MoOfMoOf Member
    Very new to php and have tried this script and had no success so after messing around with it and some other basic forms i have come up with a script that somewhat works. As of right now i can get it to send the e-mail but the attachment is showing up in the body area of the email and is showing up as what i am guessing to be the base 64 code as it looks like this


    PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
    Ly9FTiINImh0dHA6Ly93d3cudzMub3JnL1RSL2h0bWw0L2xvb3NlLmR0ZCI+DTxodG1sPg08aGVh
    ZD4NPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNo
    YXJzZXQ9aXNvLTg4NTktMSI+DTx0aXRsZT5Bbm5lJ3MgUmVudGFsczwvdGl0bGU+DTxzdHlsZSB0
    eXBlPSJ0ZXh0L2NzcyI+DTwhLS0NLnN0eWxlMSB7DQlmb250LWZhbWlseTogVmVyZGFuYSwgQXJp
    YWwsIEhlbHZldGljYSwgc2Fucy1zZXJpZjsNCWZvbnQtc2l6ZTogMjRweDsNfQ0uc3R5bGUyIHsN
    CWZvbnQtc2l6ZTogMTJweDsNCWZvbnQtZmFtaWx5OiBWZXJkYW5hLCBBcmlhbCwgSGVsdmV0aWNh

    the code i am using is as follows:




    ****** http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />




    $emailadd = 'me@mymail.com';
    $url = 'http://www.mydomain.com/confirmation.htm';
    $req = '1';
    $attachment = $_FILES['attachment']['tmp_name'];
    $attachment_name = $_FILES['attachment']['name'];
    if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $fp = fopen($attachment, \"rb\"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    }
    mail($emailadd, $message, $data);
    echo '****** HTTP-EQUIV=Refresh CONTENT=\"0; URL='.$url.'\">';
    ?>

    any help with this would be great and I would like to extend my thanks in advance.
  • MoOfMoOf Member
    scratch that last post i got it figured out thank you all for the work you have all put into this code
  • Kwitko said:
    As promised. Now I didn't add any error checking or formatting. My goal was simply to make sure the MIME encoding was done right. MIME headers are *very* finicky. If you want to add more attachments, you could foreach or while the chunk routine.

    Without further ado, I give you:

    [code]
    //EDIT: added some additional comments. I realized after posting that it's kind of silly to add the MIME boundary if you're not neccessarily sending an attachment, so the encoding routine plus the boundaries for the attachment should really be conditional. Then again, the whole purpose of this script is so you can send attachments, right?














    here is a better upgrade with error checking or formatting to your upload form and mime headers. requires little php and html knowledge


    ---enjoy







    =============================================




    <?php
    $fileatt = ""; // Path to the file
    $fileatt_type = "application/octet-stream"; // File Type
    $fileatt_name = ""; // Filename that will be used for the file as the attachment
    $email_from = ""; // Who the email is from
    $email_subject = ""; // The Subject of the email
    $email_txt = ""; // Message that the email has in it
    $email_to = ""; // Who the email is too
    $headers = "From: ".$email_from;
    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);
    $semi_rand = md5(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-part message 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\n" .
    $data . "\n\n" .
    "--{$mime_boundary}--\n";
    $ok = @mail($email_to, $email_subject, $email_message, $headers);
    if($ok) {
    echo "<font face="verdana">The file was successfully sent!";
    } else {
    die("Sorry but the email could not be sent. Please go back and try again!");
    }
    ?>










  • nsanitynsanity Member
    Just read this last page... but is there any reason you can't use this:

    http://phpmailer.codeworxtech.com/

    I use it every time I need to send attachments.
  • indizaindiza Member
    Hello all,
    I won't hold my breath waiting for a reply on a 6 month old thread, but if anyone sees this and can offer some help, it would be very much appreciated!

    I've used the original code, and modified it to have 5 slots for attachments... It works perfectly when either 4 or 5 attachments are included, but if fewer than 4 are attached, it doesn't send. It prints out the 'Mail sent' message, but no email actually arrives.

    I originally tried using the dynamic javascript code to allow users to attach as many files as they would like, but that didn't work out too well as I have very minimal experience with javascript. I was then told that users can't be able to submit more than 5 files anyway, so abandoned that idea.

    This is the file with the form:
    [HTML]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

    transitional.dtd">


    ****** http-equiv="Content-Type" content="text/html; charset=utf-8" />
    The Alliance of Dental Care Professionals******** type="text/javascript">


    ******** src="scripts/AC_RunActiveContent.js" type="text/javascript">







    Create Your

    Profile


    image































































    Practice Name:
    Dr Name:
    Street:
    City:
    Province
    Postal Code:
    Phone::
    Fax:
    Email:

    Website:



    Hours of operation:


































































    Sunday


    to



    Closed
    Monday


    to



    Closed
    Tuesday


    to



    Closed
    Wednesday


    to



    Closed
    Thursday


    to



    Closed
    Friday


    to



    Closed
    Saturday


    to



    Closed
    Request 4 photos and logo:















     


     



    [/HTML]

    and this is the formproc.php file:


    <?php

    $action = $_REQUEST['action'];
    global $action;

    function sendMyMail() {

    $to_name = \"My name\";
    $to_email = \"My email address\";
    $PracticeName = stripslashes($_POST['PracticeName']);
    $DrName = stripslashes($_POST['DrName']);
    $Street = stripslashes($_POST['textfield5']);
    $City = stripslashes($_POST['textfield6']);
    $Province = stripslashes($_POST['textfield7']);
    $PostalCode = stripslashes($_POST['zip_code']);
    $Phone = stripslashes($_POST['phone_no']);
    $Fax = stripslashes($_POST['fax_no']);
    $from_email = stripslashes($_POST['from_email']);
    $Website = stripslashes($_POST['textfield12']);
    $SunFrom = stripslashes($_POST['SunFrom']);
    $SunTo = stripslashes($_POST['SunTo']);
    $ClosedSun = stripslashes($_POST['ClosedSun']);
    $MonFrom = stripslashes($_POST['MonFrom']);
    $MonTo = stripslashes($_POST['MonTo']);
    $ClosedMon = stripslashes($_POST['ClosedMon']);
    $TuesFrom = stripslashes($_POST['TuesFrom']);
    $TuesTo = stripslashes($_POST['TuesTo']);
    $ClosedTues = stripslashes($_POST['ClosedTues']);
    $WedFrom = stripslashes($_POST['WedFrom']);
    $WedTo = stripslashes($_POST['WedTo']);
    $ClosedWed = stripslashes($_POST['ClosedWed']);
    $ThurFrom = stripslashes($_POST['ThurFrom']);
    $ThurTo = stripslashes($_POST['ThurTo']);
    $ClosedThur = stripslashes($_POST['ClosedThur']);
    $FriFrom = stripslashes($_POST['FriFrom']);
    $FriTo = stripslashes($_POST['FriTo']);
    $ClosedFri = stripslashes($_POST['ClosedFri']);
    $SatFrom = stripslashes($_POST['SatFrom']);
    $SatTo = stripslashes($_POST['SatTo']);
    $ClosedSat = stripslashes($_POST['ClosedSat']);

    $body= \"
    Practice Name: $PracticeName
    Dr Name: $DrName
    Address: $Street, $City, $Province, $PostalCode
    Phone: $Phone
    Fax: $Fax
    Email: $from_email
    Website: $Website
    Hours of Operation:

    Sunday: $SunFrom to $SunTo $ClosedSun
    Monday: $MonFrom to $MonTo $ClosedMon
    Tuesday: $TuesFrom to $TuesTo $ClosedTues
    Wednesday: $WedFrom to $WedTo $ClosedWed
    Thursday: $ThursFrom to $ThursTo $ClosedThurs
    Friday: $FriFrom to $FriTo $ClosedFri
    Saturday: $SatFrom to $SatTo $ClosedSat
    \";

    $subject= \"Membership Profile Form\";

    $filecount = 0;
    foreach($_FILES as $file => $value) {
    $attachment[(int)$filecount] = $_FILES[$file]['tmp_name'];
    $attachment_name[(int)$filecount] = $_FILES[$file]['name'];
    if (is_uploaded_file($attachment[(int)$filecount])) { //Do we have a file uploaded?
    $fp = fopen($attachment[(int)$filecount], \"rb\"); //Open it
    $data[(int)$filecount] = fread($fp, filesize($attachment[(int)$filecount])); //Read it
    $data[(int)$filecount] = chunk_split(base64_encode($data[(int)$filecount])); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    $filecount++;
    }
    }

    //Let's start our headers

    $headers = \"From: $PracticeName<\" . $_POST['from_email'] . \">\n\";
    $headers .= \"Reply-To: <\" . $_POST['from_email'] . \">\n\";
    $headers .= \"MIME-Version: 1.0\n\";
    $headers .= \"Content-Type: multipart/related; type=\\"multipart/alternative\\"; boundary=\\"----=MIME_BOUNDRY_main_message\\"\n\";


    $headers .= \"X-Sender: $from_name<\" . $_POST['from_email'] . \">\n\";
    $headers .= \"X-Mailer: PHP4\n\";
    $headers .= \"X-Priority: 3\n\"; //1 = Urgent, 3 = Normal
    $headers .= \"Return-Path: <\" . $_POST['from_email'] . \">\n\";
    $headers .= \"This is a multi-part message in MIME format.\n\";
    $headers .= \"------=MIME_BOUNDRY_main_message \n\";
    $headers .= \"Content-Type: multipart/alternative; boundary=\\"----=MIME_BOUNDRY_message_parts\\"\n\";
    $message = \"------=MIME_BOUNDRY_message_parts\n\";
    $message .= \"Content-Type: text/plain; charset=\\"iso-8859-1\\"\n\";
    $message .= \"Content-Transfer-Encoding: quoted-printable\n\";
    $message .= \"\n\";
    /* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
    $message .= \"$body\n\";
    $message .= \"\n\";
    $message .= \"------=MIME_BOUNDRY_message_parts--\n\";
    $message .= \"\n\";

    for ($i = 0, $filecount = (int) count($data); $i < $filecount; $i++) {
    $message .= \"------=MIME_BOUNDRY_main_message\n\";
    $message .= \"Content-Type: application/octet-stream;\n\tname=\\"\" . $attachment_name[$i] . \"\\"\n\";
    $message .= \"Content-Transfer-Encoding: base64\n\";
    $message .= \"Content-Disposition: attachment;\n\tfilename=\\"\" . $attachment_name[$i] . \"\\"\n\n\";
    $message .= $data[$i]; //The base64 encoded message
    $message .= \"\n\n\";
    }

    $message .= \"------=MIME_BOUNDRY_main_message--\n\";

    // send the message

    $ok = mail(\"$to_name <$to_email>\", $subject, $message, $headers);

    if($ok) {
    $result= \"Mail sent.\";
    } else {
    $result= \"There was a problem sending your message. Please go back and try again.\";
    }

    ?>
    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\">
    <head>
    ****** http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
    <title>The Alliance of Dental Care Professionals</title>******** type=\"text/javascript\">
    <!--
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf(\"#\")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    //-->
    </script>
    ******** src=\"scripts/AC_RunActiveContent.js\" type=\"text/javascript\"></script>
    <link href=\"styles.css\" rel=\"stylesheet\" type=\"text/css\" />
    </head>

    <body style= \"margin:0\">


    <table width=\"708\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
    <tr>
    <td align=\"left\" valign=\"top\" background=\"images/tblbck.jpg\" class=\"bodytext\"><span class=\"headline\">Create Your Profile</span><br />
    <img src=\"images/divider.jpg\" width=\"670\" height=\"2\" /><br />

    <table width=\"100%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
    <tr>
    <td><? echo $result; ?></td>
    </tr>
    </table>

    <p>&nbsp;</p>

    </td>
    </tr>
    </table>
    </body>
    </html>

    <?

    }

    if ($action == \"send\") {
    sendMyMail();
    }

    ?>


    Essentially, I just need users to be able to send any number of attachments between 0 and 5. This is the first time I've worked with headers and attachments and the like, so forgive me if the solution is obvious!

    Thanks in advance for any assistance anyone can offer.
  • LincolnLincoln Snapperhead Admin, Supporter, Expo Attendee
    Are you able to turn on error reporting? The easiest first step in a debug is always to see what sort of Notices or Warnings might be cropping up.

    I'm going to go out on a limb and say it's something wrong with the foreach($_FILES as $file => $value) loop. I don't know if blindly looping through the $_FILES element like that is a good idea. The only way I've done it is to individually check each possible expected field ($_FILES['attachement'], $_FILES['attachment2'], etc) and go from there.

    If it wigs out from 3 or less, I'd say that when it finds a second empty file field in the loop it's running into an error. That's my best intuitive guess from your description of the problem, anyway.
  • indizaindiza Member
    Thanks, Lincoln! I couldn't get error checking turned on, but I tried separating the foreach loops into 5 individual sections and that seemed to do the trick! Much appreciated. :)
  • LincolnLincoln Snapperhead Admin, Supporter, Expo Attendee
    Great, glad you got it working :) Thanks for letting us know.
  • verto8verto8 Member
    Q1. How do you get the original script to work with sending to multiple email addresses (multiple recipients)?

    Q2. A follow up to Q1, how can the script be adjusted so that only the "username" is required and the email sent would go to the username's account with Yahoo, Gmail, etc... as in below. One would only enter the username in the to_email field and the mailer would send emails to all the listed addresses in the array for that username.
    $username = 'to_ recipient';
    $to_email = array('to_ [email]recipient@yahoo.com[/email]', 'to_ [email]recipient@gmail.com[/email]');

    Sorry if the syntax is wrong since I am a PHP/JS newbie. Any help would be greatly appreciated. Thanks much in advance.
  • 1) I'm going to go out on a limb and say use a comma separated list i.e. ("a@ randomdomainhere.com", "b@randomdomainhere.com")

    2) You'd likely want to do one of two things, have an open dataset/array that has all of the recipients information (email, name, etc) although I'm not all THAT familiar with php at this moment. The other option is to build a multi-dimensional array of [username][email] to loop through. Personally, I'd use the unique ID of the user and not the name...otherwise you can run into some stupid stuff happening.
  • LincolnLincoln Snapperhead Admin, Supporter, Expo Attendee
    You almost wrote it yourself:

    $username = 'to_ recipient';
    $to_email = array( $username.'@yahoo.com', $username.'@gmail.com');
Sign In or Register to comment.