SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Sending Attachment not working
-
Jun 11, 2007, 23:35 #1
- Join Date
- Apr 2007
- Location
- India
- Posts
- 509
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sending Attachment not working
Hello all,
I want to send an attachment through php using php mail() function.
But my problem is I can see the attachment in my inbox but the message I have specified in $body variable is not displaying.
Could anyone suggest me what i am doing wrong in the following code?
PHP Code:$from = "email1@gmail.com";
$to = "email2@gmail.com";
$subject = "Test mail with an attachment";
$file_name = "testpage.doc";
$body = "This is a test message.This is to show how to send the attachments using simple mail() function.\n\n";
$boundary = md5(time());
$headers .= "From:".$from."\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$message .= "--".$boundary."\n";
$message .= "Content-Type: application/msword; name=\"".$file_name."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n\n";
$message .= "--".$boundary."\n";
$message .= "--".$boundary."\n";
$message .= $body;
if(!mail($to, $subject, $message, $headers))
echo "Mail Sending Failed";
else
echo "Mail Sent";
Thanks,Barbara
-
Jun 12, 2007, 00:49 #2
- Join Date
- Dec 2006
- Location
- /dev/swat
- Posts
- 619
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Change this :
PHP Code:$message .= "--".$boundary."\n";
PHP Code:$message = "--".$boundary."\n";
-
Jun 12, 2007, 02:06 #3
- Join Date
- Apr 2007
- Location
- India
- Posts
- 509
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for reply.I tried as you told me.
But now no attachment + no message at all.
PHP Code://$message .= "--".$boundary."\n"; commented
$message = "--".$boundary."\n";
$message .= $body;
Barbara
-
Jun 12, 2007, 02:35 #4
- Join Date
- Apr 2007
- Location
- India
- Posts
- 509
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cheers . Solved.
PHP Code:$from = "email1@gmail.com";
$to = "email2@gmail.com";
$subject = "Test mail with an attachment";
$file_name = "testpage.doc";
$body = "This is a test message.\nThis is to show how to send the attachments using simple mail() function.\n";
$boundary = md5(time());
$headers .= "From:".$from."\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$message .= "--".$boundary."\n";
$message .= "Content-Type: application/msword; name=\"".$file_name."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n\n";
$message .= "--$boundary\n";
$message .= "--".$boundary."\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: binary\n\n";
$message .= $body;
$message .= "--$boundary\n";
if(!mail($to, $subject, $message, $headers))
echo "Mail Sending Failed";
else
echo "Mail Sent";
Barbara
Bookmarks