Jump to content

Sending Image File From Website Form to Email address with PHP


Recommended Posts

Hey Guys,

 

Hope you can help..

 

I currently have a form which is handled by a PHP Form that works fine.

 

However I want to add a new field to the form.

 

This field is a File Field that will allow users to load an image which I then want emailed to me as an attachment to the email address within the PHP code.

 

My form is:

 

<form action="membershipReceived.php" method="post" enctype="multipart/form-data" name="membership" onsubmit="MM_validateForm('fullname','','R','profession','','R','PostCode','','R','Town/City','','R','dob','','R','email','','RisEmail');return document.MM_returnValue">
<p>
<label for="name">*Name:</label>
<input name="fullname" type="text" class="txt" id="fullname" />
</p>
<p>
<label for="gender">*Gender:</label>
<select name="gender" class="dropdown">
  <option class="txt" value="">Please Choose...</option>
  <option class="txt" value="female">Female</option>
  <option class="txt" value="male">Male</option>
</select>
</p>
<p>
<label for="Profession">*Profession:</label>
<input type="text" name="profession" id="profession" class="txt" />
</p>
<p>
<label for="PostCode">*Post Code:</label>
<input type="text" name="postcode" id="postcode" class="txt" />
</p>
<p>
<label for="Town/City">*Town/City:</label>
<input type="text" name="town" id="town" class="txt" />
</p>
<p>
<label for="dob">*DOB (dd/mm/yyyy):</label>
<input type="text" name="dob" id="dob" class="txt" />
</p>
<p>
<label for="picture">*Your Picture:</label>
<input type="file" name="picture" class="txt" />
</p>
<p>
<label for="email">*Email:</label>
<input type="text" name="email" id="email" class="txt" />
</p>
<p>
<label for="mobile">*Mobile:</label>
<input type="text" name="mobile" id="mobile" class="txt" />
</p>
<p>
<input type="submit" name="btnSubmit" id="btnSubmit" value="Sign Up!" class="btn" />
</p>
</form>

 

and the PHP code which handles this is:

 

<?php











$EmailFrom = Trim(stripslashes($_POST['email'])); 



$EmailTo = "email@email.co.uk";



$Subject = " MEMBERSHIP"; 



$fullname = Trim(stripslashes($_POST['fullname'])); 



$gender= Trim(stripslashes($_POST['gender'])); 



$profession = Trim(stripslashes($_POST['profession'])); 



$postcode = Trim(stripslashes($_POST['postcode']));



$town = Trim(stripslashes($_POST['town'])); 



$dob = Trim(stripslashes($_POST['dob'])); 



$picture = Trim(stripslashes($_POST['picture'])); 



$email = Trim(stripslashes($_POST['email'])); 



$mobile = Trim(stripslashes($_POST['mobile'])); 







// validation



$validationOK=true;



if (Trim($EmailFrom)=="") $validationOK=false;



if (!$validationOK) {



print "ERROR";



exit;



}







// prepare email body text



$Body = "";



$Body .= "fullname: ";



$Body .= $fullname;



$Body .= "\n";



$Body .= "gender: ";



$Body .= $gender;



$Body .= "\n";



$Body .= "profession: ";



$Body .= $profession;



$Body .= "\n";



$Body .= "postcode: ";



$Body .= $postcode;



$Body .= "\n";



$Body .= "town: ";



$Body .= $town;



$Body .= "\n";



$Body .= "DOB: ";



$Body .= $dob;



$Body .= "\n";



$Body .= "Picture: ";



$Body .= $picture;



$Body .= "\n";



$Body .= "email: ";



$Body .= $email;



$Body .= "\n";



$Body .= "mobile: ";



$Body .= $mobile;



$Body .= "\n";



$Body .= "\n";











// send email 



$success = mail($EmailTo, $Subject, $Body, "From: <$email>");







// redirect to success page 



if ($success){



echo "<p >Thank you <b>$fullname</b></p>



<p>We will soon send you our weekly newsletter and regular updates to <b>$email.</b></p>



<p>We will also send you text invites to <b>$mobile.</b></p>



<p>If this email address or mobile number is incorrect please go back and re-enter your details.</p>



<p>All texts sent to you are free of charge.</p>



<p>All data data sent to uswill be kept safe and will be used by Elite Clubbing only.</p>



<p>Many Thanks,</P>";







} else {







//You can delete this and put a redirect script like the thank you above



echo "ERROR";



}



?>

 

I would like to keep this code if I can but modify it so the PHP code handles the file field, attaches it to the email which i will then receive to my email address...

 

I'm not the best PHP coder and this is out of my knowledge base! If you can help my do this I'd would great appreciate this. i have about 24 hours to do this!!

 

thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.