Reputation: 1
i'm new in PHP and i want to send image which is upload by user from his/her computer in mail i'm using PHPMailer. Please give way with example with different file.
file1.php
< input type="file" id="lcimage" name="image" />
file2.php
$LC = $_POST['image'];
$mail->AddEmbeddedImage($LC, 'lcimage', $LC);
<img src="" />
Upvotes: 0
Views: 4589
Reputation: 156
use this..
$mail->IsHTML(true);
$mail->AddEmbeddedImage('logo.jpg', 'logoimg');
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test picture: <img src=\"cid:logoimg\" /><img src=\"cid:logo2img\" /></p>";
hope this will help you
Upvotes: 0
Reputation: 2512
file type elements are not added in $_POST variable. There is a different super global available for uploaded files i.e. $_FILES
First thing, make sure you have added enctype="multipart/form-data" attribute in your form otherwise uploaded file elements will not be received in $_FILES
<form method="post" action="process.php" enctype="multipart/form-data">
<input type="file" id="lcimage" name="image" />
</form>
And for adding this file in the email you can use this code.
$mail->AddAttachment($_FILES['image']['tmp_name'],
$_FILES['image']['name']);
Upvotes: 3