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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending a file attachment

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a form that people fill out. Now I am able to grab the data. But the problem is I need to put this data into a file and then send this file as an attachment to an email address. I do not know how to even begin to create the file. I DO however have the capability of sending the email, but it isn't sending the file correctly. all i get is a bunch of letters that make no sense in the email message, instead of the attached file i want. can anyone help.

Here's the code that i have:
$txt = "comma delimited form data"

$filename = "mail/df". $datetimestamp . ".csv";
print "The filename: " . $filename . " has been assigned.";

//opening file to write to
$fp = fopen("$filename","a+");

//writing data to file
$write_data = fputs($fp,$txt);

if (is_file($filename))
{
print $filename . " EXISTS";
print $write_data . &quot;<br>&quot;;

//making sure data was written
if ($write_data)
{ print(&quot;<CENTER><H3>Successfully added data</H3><BR>(automatic forward in 5 seconds)</CENTER>&quot;); }
else
{ print(&quot;<CENTER><H3><FONT COLOR='#FF0000'>Unsuccessful</FONT> added data </H3><BR>(automatic forward in 5 seconds)&quot;); }
}

include(&quot;../slugs/mime_mail.inc&quot;);

//Sends the email with the attachment.
$mail=new mime_mail;
$mail->from = &quot;from@mydomain.com&quot;;
$mail->to = &quot;to@mydomain.com&quot;;
$mail->subject = &quot;Testing Send Mail&quot;;
$mail->body = $msg;
$content_type = &quot;plain/text&quot;;
$mail->add_attachment($txt,$filename,$content_type);
$mail->send();

fclose($fp);
unlink($filename);

Thank You in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top