Jump to content

PHP PEAR email attachment


amrita

Recommended Posts

$file_field_name = "file";$submit_field_name = "upload";$upload_dir = "attach/";if (isset($_POST[$submit_field_name])){ # Check if there is a file if (is_uploaded_file($_FILES[$file_field_name]["tmp_name"])){ if (move_uploaded_file($_FILES[$file_field_name]["tmp_name"], $upload_dir.basename($_FILES[$file_field_name]["name"]))){ $filename = basename($_FILES[$file_field_name]["name"]); echo "File successfully attached:<br /><br /> $filename <img src=\"".$upload_dir."/".$filename."\"><br /><br />"; }else{ echo "There were some errors!"; } }}# There's random server info here and stuff# There's random server info here and stuff# There's random server info here and stuff# There's random server info here and stuff$message = new Mail_mime();$message->setTXTBody($text);$message->setHTMLBody($html);$message->addAttachment("What do I type here to make it use the latest uploaded file and send it along with the email");---I cannot seem to make it send the attachment with the email, it simply uploads the file to a folder, which is not what I want.Can anyone help?

Link to comment
Share on other sites

It needs to upload the file before it can attach it to anything. I'm sure you probably just put the filename that you want to attach into the addAttachment method, but you can check the documentation for that to find out for sure. The filename after it gets moved is: $upload_dir.basename($_FILES[$file_field_name]["name"]

Link to comment
Share on other sites

Permission denied means you don't have permission to open the file. Add a line after the if statement to set permissions.if (move_uploaded_file($_FILES[$file_field_name]["tmp_name"], $upload_dir.basename($_FILES[$file_field_name]["name"]))){chmod($upload_dir.basename($_FILES[$file_field_name]["name"]), 0644);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...