/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] phpmailer email sent but no attachment

I am using the below script to allow user to upload images and email it to me. I did received the email but there is no attachment. It also show the from email as root user instead of the user’s email address. please help.

[code=php]<?php
ob_start();
require(“class.phpmailer.php”);

$salutation = $_POST[‘salutation’];
$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$email = $_POST[’email’];
$photo = $_FILES[‘photo’];

isset($_POST[‘submit’]);
$active_keys = array();
foreach($_FILES[$photo][‘name’] as $key => $filename)
{
if(!empty($filename))
{
$active_keys[] = $key;
} }

foreach($active_keys as $key)
{ switch(exif_imagetype($_FILES[$photo][‘tmp_name’][$key])) {
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
break;
default:
echo “{“;
echo “error: ‘This is no photo..’n”;
echo “}”;
exit(0);
} }
$message = “Photo submitted by: $salutation $firstname $lastname. <br>Comments: $comments.<br>terms:$terms.”;

$mail = new PHPMailer();

$mail->From = ($email);
$mail->AddAddress(‘[email protected]’);

$mail->Subject = “Submitted Photos”;
$mail->Body = $message;
$mail->WordWrap = 50;

foreach($FILES[‘photo’][‘tmp_name’] as $photo) {
if(!empty($photo)) {
$mail->AddAttachment($photo);
}}

$mail->Send();

header(“Location: thankyou.php”);
exit();

?>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@chrisranjanaMar 26.2013 — foreach($FILES['photo']['tmp_name'] as $photo) {

should be

foreach($[B]_[/B]FILES['photo']['tmp_name'] as $photo) {
×

Success!

Help @phpnewbie08 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...