0

i need help with html form that send mail via PHP with image attachment, i tried simple code and the message was sent, there is all texts and even image name but no actual image, i´m not exactly sure how to do it propperly i tried many codes but none of them works. Im horible sorry if this was already answered but i searched for few hours and could not find anything.

here is my html

<div class="uk-alert uk-alert-large uk-alert-success" style="float: right; width: 25%; padding: 30px;">Registration for competitors
<form action=".../registration.php" method="POST" enctype="multipart/form-data">
<br />Full Name:<br /> <input type="text" name="name" required/> 
<br /> Country: <br />*At least one team member has to have the citizenship of the chosen country.
<br /><input type="text" name="krajina" required/> <br /> Full name of your team mate:<br />
<input type="text" name="tym" required/> 
<br /> Email:<br /> 
<input type="text" name="email" required/> At least 3 pictures of your previous work: 
<input id="fileToUpload" placeholder="Select an image to Upload" type="file" name="fileToUpload" required/> 

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$tym = $_POST['tym'];
$krajina = $_POST['krajina'];
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
$formcontent=" Uzivatel: $name \ email: $email \ jeho kolega: $tym \ z krajiny: $krajina \ sa hlasi na event Tatry ice master chalenge 2016 \ $target_file" . "\r\n";
$recipient = "test@mail.com";
$subject = "Registracia na Specialny Event";
$mailheader =  "From: $email\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo header("Location: http://www.iceart.club/special-events");
die();
?>
thank you all for any help
5vkr08
  • 43
  • 4

2 Answers2

0

try this link here

To use PHPMailer:

  • Download the PHPMailer script from here: http://github.com/PHPMailer/PHPMailer

  • Extract the archive and copy the script's folder to a convenient place in your project.

  • Include the main script file -- require_once('path/to/file/class.phpmailer.php');

Now, sending emails with attachments goes from being insanely difficult to incredibly easy:

$email = new PHPMailer();
$email->From      = 'you@example.com';
$email->FromName  = 'Your Name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );

return $email->Send();

It's just that one line $email->AddAttachment(); -- you couldn't ask for any easier.

If you do it with PHP's mail() function, you'll be writing stacks of code, and you'll probably have lots of really difficult to find bugs.

Community
  • 1
  • 1
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
  • thank you very much i´m gonna try it probbably the best possible solution i spend too much time on this stupid little code – 5vkr08 May 28 '15 at 13:24
0
$mail->AddEmbeddedImage('img/2u_cs_mini.jpg', 'logo_2u');

and on the tag put src='cid:logo_2u'

Alpesh Rathod
  • 385
  • 3
  • 10
  • sorry but how exactly would this help me? i don´t need src for image i need to upload it and then send it but thanks anyway – 5vkr08 May 28 '15 at 13:46