submit text from field AND file to email

http://www.foxenews.com/submitPHP.zip

Link above contains the files I am looking to resolve a few issues. I have what appears to be 3 issues. The “submitscreenshot.png” is what I get when I hit the “submit” button. So this is telling me something and I am stuck as I have no idea what it means. So that’s issue #1. #2 is I am receiving 2 emails where I would like to receive 1 email with everything in it. Issue #3 is I am not receiving an attachment as the email is coming in as shown in “emailscreenshot.png”. It is worth noting that 1 of the 2 emails is successfully working. The one that is working is the one that has the input forms, the attachment email is the one that is not working (I would like to combine the 2).

I am new to php and I am trying to combine 2 php scripts from 2 different people and make it 1 script. I couldn’t find a tutorial on how to do it all in one so I have attempted it on my own and gotten fairly far.

My goal for this php script: When I hit the submit button, it will submit 1 email with all fields filled out plus a file attachment the user has selected from their computer.

Below is the link to the php tutorial I used for submitting a photo to an email.
http://www.youtube.com/watch?feature=endscreen&NR=1&v=0y7a00iLYj8

post the code for both scripts make sure you put them inside php block

Here you go. I have 4 scripts. Sorry about the first one being lengthy. Included are links to the screenshots as mentioned in my first post.
http://www.foxenews.com/submitscreenshot.png
http://www.foxenews.com/emailscreenshot.png
[php]<?php include("privateheader.php"); ?>

Article Submission Form

Use this form to submit your article. Please follow these guidelines so I don't have to contact you to ask questions.

  • Your name
  • Date you want to appear on the web page next to your article.
  • Title for your article (47 characters max. including spaces).
  • Brief summery to go under your title. This is for the front page only. Possibly may be used when we archive. (250 characters max. including spaces)
  • Category is your article going to be placed under. (Sports, Tech, News, Video, Entertainment or new category
    if you have more articles you would like to submit)
  • Submit 2 photos that have not been shrunk down to any size. If it is a lengthy article, submit a few more photos up to 5.
  • Rename the photos so they identify with the article and please keep the name in all lower case letters with no spaces,
    it makes it much easier for me to post. Please don't name the photo july4thparade.jpg, name it something like july4thfiretruck2012.jpg.
    Adding the year in the name of the photo is a good idea because next year we may cover the 4th of July parade again.
  • Please make sure spell checking and grammar is done prior to submitting. I do not check your articles before they are posted.
  • If you want to submit a link to your personal web page, feel free to do so. It will be placed at the bottom of your article as a link.
  • This form does not automatically post your article when you submit it. This post will be emailed to me and then I will manually put it up on the web page.
    If this form gives you some sort of error, please email me all the info you would normally fill out to [email protected]
  • If you would like to include a small profile picture of your face to go with your article, include it in your attachments when sending your article.


  • Full Name
    Your Email
    Date for Article
    Title
    Article Summery
    Category
    Link
    Article Copy and paste your article in here or browse to the file by using the ATTACH DOCUMENT button below.
    Filename:
    <?php include("privatefooter.php"); ?>[/php]

    Script #2
    [php]<?php
    include(‘init.inc.php’);
    if (isset($_POST[‘name’], $_FILES[‘file’])){
    $body = <<<BODY
    From: {$_POST[‘name’]}

    Details:
    	Name:	{$_FILES['file']['name']}
    	Size:	{$_FILES['file']['size']}
    	Type:	{$_FILES['file']['type']}
    

    BODY;
    mail_file(‘[email protected]’, ‘Article Submission’, $body, $_FILES[‘file’]);
    }

    $to=‘[email protected]’;
    $subject='Article Submission from ’ . $name;

    $name=$_POST[‘name’];
    $email=$_POST[‘email’];
    $date=$_POST[‘date’];
    $title=$_POST[‘title’];
    $summery=$_POST[‘summery’];
    $category=$_POST[‘category’];
    $link=$_POST[‘link’];
    $message=$_POST[‘message’];
    $message="Name: ".$name. “\r\n” . "Email: " .$email . “\r\n” . "Article Date: " .$date . “\r\n” . "Title: " .$title . “\r\n” . "Summery: " .$summery . “\r\n” . "Category: " .$category . “\r\n” . "Link: " .$link . “\r\n” . "Message: " .$message;

    mail($to,$subject,$message);
    echo ‘Thanks for your submission. I will post your article soon!’;

    ?>



    back to home page [/php]

    Script #3
    [php]<?php
    $path = dirname(FILE);
    include("{$path}/mail.inc.php");
    ?>[/php]

    Script #4
    [php]<?php

    function mail_file($to, $from, $subject, $body, $file){
    $boundary = md5(rand());

    $headers = array(
    	'MIME-Version: 1.0',
    	"Content-Type: multipart/mixed: boundary=\"{$boundary}\"",
    	"From: {$from}"
    );
    
    $message = array(
    	"--{$boundary}",
    	'Content-Type: text/plain',
    	'Content-Transfer-Encoding: 7bit',
    	'',
    	chunk-split($body),
    	"--{$boundary}",
    	"Content-Type: {$file['type']}; name=\"{$file['name']}\"",
    	"Content-Disposition: attachment; filename=\"{$file['name']}\"",
    	"Content-Transfer-Encoding: base64",
    	'',
    	chunk_split(base64_encode(file_get_contents($file['tmp_name']))),
    	"--{$boundary}--"
    );
    
    mail($to, $subjet, implode("\r\n", $message), implode("\r\n", $headers));
    

    }

    ?>[/php]

    Sponsor our Newsletter | Privacy Policy | Terms of Service