Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

phpMailer and attachments

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
hello - I followed your advice and got phpmailer - however as a newbie to php I need more assistance.

I am using the following php code to upload a graphic file to my server and following it with the phpmailer code to send an email - so my php script looks likes this:
Code:
//move the uploaded file 
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);

$mail = new PHPMailer();


$mail->From     = "whoknows361@msn.com";
$mail->FromName = "Jon";
$mail->AddAddress("myemail@myemail.com","Jonathan"); 
$mail->AddReplyTo("myemail@myemail.com","Jonathan");

$mail->WordWrap = 50;                              // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); 
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the <b>HTML body</b>";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

Now on the attachment line in the phpmailer code it shows:
$mail->AddAttachment("/var/tmp/file.tar.gz");
But I need to change this to the image file which was identified in the first few lines.. How do I do this?
How can I reference the image file?
Your help is GREATLY appreciated.

Jonathan
 
please take the time to learn some php basics. read the manual, go on a training course, follow some tutorials...

the code below uses variables (big section in the manual on these). but you could equally have referenced the full path
Code:
"./files/".$_FILES['Filedata']['name']

Code:
//move the uploaded file 
$file = "./files/".$_FILES['Filedata']['name'];
if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $file)){
 $cm = umask(0);
 chmod$file, 0777);
 umask($cm);
 $mail = new PHPMailer();
 $mail->From     = "whoknows361@msn.com";
 $mail->FromName = "Jon";
 $mail->AddAddress("myemail@myemail.com","Jonathan"); 
 $mail->AddReplyTo("myemail@myemail.com","Jonathan");

 $mail->WordWrap = 50;                              // set word wrap
 $mail->AddAttachment($file); 
 $mail->IsHTML(true);                               // send as HTML

 $mail->Subject  =  "Here is the subject";
 $mail->Body     =  "This is the <b>HTML body</b>";
 $mail->AltBody  =  "This is the text-only body";

 if(!$mail->Send())
 {
    echo "Message was not sent <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
 }
 echo "Message has been sent";
}// end of if move uploaded file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top