Custom Email Script Request - PHP

edited February 2008 in Internet & Media
Ok, I don't know how hard this would be for someone. But I would like to request a custom script for my website, the form will have will something like this.
To: Email@com.org
Subject: The Turtle
Message: Hey mr turtle
File: file
Attach Another?
[Send]
The names would be like this.
name="to,sub,mes,file,add,send"
Any questions just ask me. Thanks to anyone who replies. I might not respond immediately because I am going out to CiCi's in a minute. Thanks and have a good day.

~Carl

Comments

  • edited February 2008
    I can probably do it tomorrow. Adding multiple attachments might be hard for me but I'll try.

    Edit: I actually found a topic here with the answer to your problem.

    http://icrontic.com/forum/showthread.php?t=7019

    If you don't understand it then just ask away and I could modify it for your needs.
  • edited February 2008
    No I do not understand it all that much. I know what the form contents do, but I do not have any knowledge of PHP at the moment. Could you explain how I install/place his script?
  • edited February 2008
    I modified it a bit and it should work as you want.

    Just modify this line to your email.

    [PHP]$to_email = "Your email here";[/PHP]

    Full code here.

    [PHP]
    <?php
    /* Mailer with Attachments */

    $action = $_REQUEST;
    global $action;

    function showForm() {
    ?>

    <form enctype="multipart/form-data" name="send" method="post" action="<?=$_SERVER?>">
    <input type="hidden" name="action" value="send" />
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    <p>From Name:<br> <input name="from_name" size="50" /><br>
    From Email:<br> <input name="from_email" size="50" /><br>
    Subject:<br> <input name="subject" size="50" /><br>
    Message:<br> <textarea name="body" rows="10" cols="50"></textarea><br>
    Attachment:<br> <input type="file" name="attachment" size="50" />
    <input type="submit" value="Send Email" /></p>

    <?php
    }

    function sendMail() {
    if (!isset ($_POST)) { //Oops, forgot your email addy!
    die ("<p>Oops! You forgot to write your email address! Click on the back arrow to go back</p>");
    }
    else {
    $to_email = "Your email here"; // Put your email here.
    $from_name = stripslashes($_POST);
    $subject = stripslashes($_POST);
    $body = stripslashes($_POST);
    $attachment = $_FILES;
    $attachment_name = $_FILES;
    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: $from_name<" . $_POST . ">\n";
    $headers .= "Reply-To: <" . $_POST . ">\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 . ">\n";
    $headers .= "X-Mailer: PHP4\n";
    $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
    $headers .= "Return-Path: <" . $_POST . ">\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";
    $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";

    // send the message
    mail("$to_name<$to_email>", $subject, $message, $headers);
    print "Mail sent.";
    }
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml&quot; xml:lang="en" lang="en">
    <head>
    <style="css" type="text/css">
    <!--
    body {
    margin: 0px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    }
    a {color: #0000ff}
    -->
    </style>
    </head>
    <body>

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

    </body>
    </html>[/PHP]

    If you need any more help, like implanting it then just ask. I will need the homepage file to implant it so if it comes to that just post it.
Sign In or Register to comment.