473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to send mail with attachment in php

Exactly the question is i have a code that is working fine in sending mail with attachments, but when the mail is sent to yahoo address the attachment file is not displaying ? Why this is happening where as it works fine for gmail, mydomain mails displaying the attachment !
Jan 24 '09 #1
7 3318
Markus
6,050 Expert 4TB
It sounds like a security measure implemented in Yahoo. Maybe, like in Hotmail, you can confirm the message is not spam, somehow? What mime type do you use?
Jan 24 '09 #2
Here is my code
Expand|Select|Wrap|Line Numbers
  1. $id=$_SESSION['mailid'];
  2.   $sub=$_POST[subj];
  3.   $msg=$_POST[message];
  4.    $body=       "----------------------------Messagee--------------------------------\n" .
  5.               "$msg\n";
  6.   $from="info@gokulmarriage.com";
  7.    "Upload: " . $_FILES["fileatt"]["name"] . "<br />";
  8.  "Type: " . $_FILES["fileatt"]["type"] . "<br />";
  9.  "Size: " . ($_FILES["fileatt"]["size"] / 1024) . " Kb<br />";
  10.  "Temp file: " . $_FILES["fileatt"]["tmp_name"] . "<br />";
  11.  
  12. if(is_uploaded_file($_FILES["fileatt"]["tmp_name"]))
  13.                         {
  14.                         $tmpname=$_FILES["fileatt"]["tmp_name"];
  15.                         $orgname=$_FILES["fileatt"]["name"];
  16.                         $fileUp=time()."_".$orgname;
  17.                         $dest="uplode_file/".$fileUp;
  18.                      move_uploaded_file($_FILES["fileatt"]["tmp_name"],
  19.                     "uplode_file/" . $fileUp);
  20.                      "Stored in: " . "uplode_file/" . $fileUp;
  21.  
  22.                         } 
  23. $fileatt = $dest; // Path to the file
  24. $fileatt_type = $_FILES["fileatt"]["type"]; // File Type
  25. $fileatt_name = $_FILES["fileatt"]["name"]; // Filename that will be used for the file as the attachment
  26.    foreach ($id as $value)
  27.         {
  28.              "$value is checked";
  29.              $sat="select * from  registration where reg_id='$value' ";
  30.             $res_del=mysql_query($sat);
  31.             $row=mysql_fetch_object($res_del);
  32.             $toemail=$row->email;    
  33.             $headers = "From: $from";
  34.              $fileatt= $dest;
  35.          $file = fopen($fileatt,'rb');
  36.          $data = fread($file,filesize($fileatt));
  37.          fclose($file);
  38.            // Generate a boundary string
  39.          $semi_rand = md5(time());
  40.          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  41.  
  42.          // Add the headers for a file attachment
  43.          $headers .= "\nMIME-Version: 1.0\r\n" .
  44.                      "Content-Type: multipart/mixed;\n" .
  45.                      " boundary=\"{$mime_boundary}\"\r\n\r\n";
  46.                      // Add a multipart boundary above the plain message
  47.          $message = "This is a multi-part message in MIME format.\r\n\r\n" .
  48.                     "--{$mime_boundary}\r\n" .
  49.                     "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
  50.                     "Content-Transfer-Encoding: 7bit\r\n\r\n" .
  51.                     $body . "\r\n\r\n";
  52.                     // Base64 encode the file data
  53.          $data1= chunk_split(base64_encode($data),72);
  54.          // print("<pre>$data1</pre>");
  55.          // Add file attachment to the message
  56.          $message .= "--{$mime_boundary}\r\r" .
  57.                      "Content-Type: {$fileatt_type};\r\n" .
  58.                      " name=\"{$orgname}\"\r\n" .
  59.  
  60.                       "Content-Disposition: attachment; filename=\"{$orgname}\"\r\n" .
  61.                        "Content-Transfer-Encoding: base64\r\n\r\n" .
  62.                       $data1 . "\r\n\r\n" .
  63.                      "--{$mime_boundary}--\r\n\r\n\r\n";
  64.  
  65.             $ok = @mail($toemail, $sub, $message, $headers);
  66.             if ($ok)
  67.                  {
  68.            echo "sent";
  69.                  } 
  70.             else
  71.                  {
  72.             echo "Failed";
  73.                  }        
  74.  
Jan 24 '09 #3
No the message is not spam.
Jan 24 '09 #4
pbmods
5,821 Expert 4TB
Heya, Ravigandha.

Are only certain types of files not showing up, or is Yahoo blocking all your attachments?
Jan 24 '09 #5
I think yahoo and hotmail is blocking all the attachments and displaying it in junk format ! Where as in others it is displaying attachments !
Jan 26 '09 #6
pbmods
5,821 Expert 4TB
Sounds like an issue you need to take up with Yahoo. The problem is in their policy, not your code.
Jan 27 '09 #7
TheServant
1,168 Expert 1GB
Yeah, spam checkers are often treating my emails as spam because they include some key spam words in the subject (Register, Sign up, etc) as well as my site not being well known. Spam protection is very tight on some mail servers where you are guilty until proven innocent, so have a play around with wording in subject, content and attachment names and see if that helps.
Jan 28 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: marsandys | last post by:
Hello, I have this code below, which I am trying to have it send HTML formatted mail with embedded images. I can get this to send the mail, but it spits out a bunch of junk . I know this should...
2
by: Robbie De Sutter | last post by:
Hello, How do I open a new, empty e-mail message from the default e-mail client whereby the sender is given and a file is attached? Currently I use the command (vb.net): ---...
2
by: m_evergreen | last post by:
Errors: An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll Additional information: Could not access 'CDO.Message' object. innerexception is "Exception has...
2
by: Cimento Cola | last post by:
Hello all. Hope anyone can help me! I have this form, with: Please choose your file: (browse) The main purpose is the user to select a local file and then when he submits a mail should be...
4
by: Max | last post by:
hi I am using System.Web.Mail.MailMessage with System.Web.Mail.SmtpMail to send mail. now the my question is, Is it compulsory to add fields smtpauthenticate, sendusername and sendpassword...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
1
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send...
1
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.