multipart emiail forms


Posted on 16th Feb 2014 07:03 pm by admin

Hi All,

I am new to the boards and I've been working on a form (which is rather massive, imo) and i've been looking online at other peoples php examples for multipart emails. The code i am using / editing (trying to learn and understand it) is one of the web examples I found..... I have some questions:

Did you know?Explore Trending and Topic pages for more stories like this.
1) onSubmit my action attribute is calling <someReuest.php>, is this a good idea? I assume yes.

Code: <form id="1" enctype="multipart/form-data" name="siteRequest" onSubmit="return validate()" method="post" action="someReuest.php">
2) in my php file i'm creating a new variable for each form field (before beinging to process anything)
e.g. $headerimage = $_POST['headerimage']; where header image is the name of one of my form fields. Is this a good practice or is this an unnecessary step?

3) I have 10 form fields of type=file thus do I need to loop over my mail attachment function? see below. Again, this function was found on the internet which i'm trying to edit, work with, learn, etc..


I know using someone else code isn't a good idea, but i'm trying to learn, and multipart isn't the easiest thing for a newb to learn.

function mail_attachment ($from , $to, $subject, $message, $attachment) {
//posting attachment to mail

$fileatt = $attachment; //path to file
$fileatt_type = "image/jpeg"; //filetype
$start = strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
$fileatt_name = substr($attachment, $start, strlen($attachment)); //file name used for attachment


$email_from = $from; //who e-mail is from
$email_subject = $subject; //subject of e-mail
$email_txt = $message; //message that the emal has in it
$email_to = $to; //who the email is to

$headers = "From: ".$email_from;

if(!($file = fopen($fileatt,'rb'))) echo "Failed To Open File $fileatt"; //read binary bytes
$data = fread($file,filesize($fileatt));
fclose($file);

$msg_txt="nn There is an attachment with this request, please review. The message came from: $from";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x($semi_rand)x";
$headers .= "nMIME-Version: 1.0n" .
"Content-Type: multipart/mixed;n" .
" boundary="{$mime_boundary}"";
$email_txt .= $msg_txt;
$email_message .= "This is a multipart message in MIME format.nn" .
"--{$mime_boundary}n" .
"Content-Type:text/html; charset="iso-8859-1"n" .
"Content-Transfer-Encoding: 7bitnn" .
$email_txt . "nn";
$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: base64nn" .
$data . "nn" .
"--{$mime_boundary}--n";


$ok = mail($email_to, $email_subject, $email_message, $headers);


if($ok)
{
echo "File Sent Successfully.";
unlink($attachment); //delete file off server after its attached
}
else
{
die("Sorry the email could not be sent.");
}
}


This is a good start I know there will be more, but i'll try to use the helpful suggestions for these first 3 questions first.

Sorry if there isn't enough code here, let me know if more needs to be added
No comments posted yet

Your Answer:

Login to answer
228 Like 5 Dislike
Previous forums Next forums
Other forums

having probem inserting data into db table
hi

i have a table with following columns in it
Code: candidate_id, degree, cgpa, institute

Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:
Code: [General]
Online=0
I wou

Join Query Help
Hi all,

I am having problems with the below code, which we shall call 'my first join query'!

WHYISNT THIS MYSQL STATEMNT NOT WORKING? (php)
caps because its absolutely rediculous.
i dontunderstand why its not working. there is a column c

random generation
hi

i need help with generating this

numbers from 1-12

i want to generate in ran

how to get values from $_Post with onchange="form.submit();"?
Hi, I have a form that submit to itself with a file upload field and two other hidden field values.<

Pro-rata Billing in Periodic Billing for Rental
Hi guys,

We have a situation, where a rental contract starts at the mid of the month say

Typedef struct vs just struct
Anyone know the rationale for using typedef for structs when a struct is itself a typedef? I have s

Problem with Subscreen
Dear Experts ,
I am facing a problem with the subscreens. My senario is as follows :

PHP - HTML
Could anyone give me some GOOD sample links for php - html email tutorial.

Thanks!

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash