473,386 Members | 1,715 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,386 software developers and data experts.

How to sending mail with attachment?

Hi All,

Can anyone guide me I want to send attachment with my mail and I'm using http://demo.tutorialzine.com/2013/05...e-upload-form/ plugin instead of simple <input type="file"/>, the issue is occurring when I'm sending mail using above given plugin I'm not receiving attachment and when I'm simply put <input type="file"/> it works perfectly.

PHP code that I've added is:

Expand|Select|Wrap|Line Numbers
  1. $errors = '';
  2. $to = "abc@gmail.com";
  3.  
  4.  
  5.  
  6. if(empty($_POST['name'])  || 
  7.  empty($_POST['email']) || 
  8.  empty($_POST['website']))
  9. {
  10.    $errors .= "\n Error: all fields are required";
  11. }
  12.  
  13. $name = $_POST['name']; 
  14. $email_address = $_POST['email'];
  15. $website = $_POST['website'];
  16. $company = $_POST['company'];
  17.  
  18.  
  19.  
  20. if (!preg_match(
  21. "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
  22. $email_address))
  23. {
  24.    $errors .= "\n Error: Invalid email address";
  25. }
  26.  
  27.  
  28.  
  29. function getSiteTitle(){ 
  30. $RefURL = (is_null($_SERVER['HTTP_REFERER'])) ? 'Un know' : $_SERVER['HTTP_REFERER'];
  31.   if($RefURL != 'Un know'){
  32.    $con = file_get_contents($RefURL) or die (" can't open URL referer ");
  33.    $pattern = "/<title>(.+)<\/title>/i";
  34.    preg_match($pattern,$con,$match);
  35.    $result = array($match[1],$RefURL);
  36.    return $result;
  37.   }
  38.   else{
  39.    return false;
  40.   }
  41. }
  42.  
  43. $info = getSiteTitle();
  44. $subject =  $info[0];
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. $message = "Message goes here..".
  53.     "Here are the details: \n \n Name : $name \n Email : $email_address \n Website : $website \n Company : $company"; 
  54.  
  55.  
  56.     $headers = "From: $to\n"; 
  57.     $headers .= "Reply-To: $email_address";
  58.  
  59.  
  60.  
  61.   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
  62.          $headers = "From: $to \r\n" .
  63.          "MIME-Version: 1.0\r\n" .
  64.             "Content-Type: multipart/mixed;\r\n" .
  65.             " boundary=\"{$mime_boundary}\"";
  66.          $message = "This is a multi-part message in MIME format.\n\n" .
  67.             "--{$mime_boundary}\n" .
  68.             "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
  69.             "Content-Transfer-Encoding: 7bit\n\n" .
  70.          $message . "\n\n";
  71.          foreach($_FILES as $userfile)
  72.          {
  73.             $tmp_name = $userfile['attachFile'];
  74.             $type = $userfile['type'];
  75.             $name = $userfile['name'];
  76.             $size = $userfile['size'];
  77.             if (file_exists($tmp_name))
  78.             {
  79.                if(is_uploaded_file($tmp_name))
  80.                {
  81.                   $file = fopen($tmp_name,'rb');
  82.                   $data = fread($file,filesize($tmp_name));
  83.                   fclose($file);
  84.                   $data = chunk_split(base64_encode($data));
  85.                }
  86.                $message .= "--{$mime_boundary}\n" .
  87.                   "Content-Type: {$type};\n" .
  88.                   " name=\"{$name}\"\n" .
  89.                   "Content-Disposition: attachment;\n" .
  90.                   " filename=\"{$fileatt_name}\"\n" .
  91.                   "Content-Transfer-Encoding: base64\n\n" .
  92.                $data . "\n\n";
  93.             }
  94.          }
  95.          $message.="--{$mime_boundary}--\n";
  96. if (mail($to, $subject, $message, $headers))
  97.    header('Location: thank-you.html');
  98. else
  99.    echo "Error in mail";
  100.  
  101. ?>
Thanks in advance!
Apr 2 '15 #1
0 1258

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

Similar topics

1
by: Fraser S | last post by:
Hi, I am receiving an invalid mail Attachment error when trying to send an attachment using System.Web.Mail. I have read other posts on these errors and have since checked that the asp.net account...
1
by: Cantekin Guneser | last post by:
i am writing wep app. and i send mail from one page , i need to ad attacment to mail whic is at client, i am doing as folloving copying file to server adding attacment to mail sending mail then...
1
by: Cantekin Guneser | last post by:
i am writing wep app. and i send mail from one page , i need to ad attacment to mail whic is at client, i am doing as folloving copying file to server adding attacment to mail sending mail then...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
2
by: Ray | last post by:
Hi Can anyone help with something that has beaten me. I am sending an email with an attachment, as per below. If I comment out the MailAttachment line then the mail gets sent, but with it in I...
0
by: Parz | last post by:
Hi can somebody please help me.. I have a web page from which the new members can mail me with their details.What i have done is, I have created a form with all details and an attachment upload...
8
by: =?Utf-8?B?cm95SGU=?= | last post by:
I have a web service. It creates a email and attached a file sitting one the network drive \\servername\filename. I tried UNC format and also try to mapping drive (eg. g:\text.txt or...
0
by: kencana | last post by:
Hi all, I got problem in sending email with image file attached. the problem is that i can't see the image, apart from that i also try to attach a txt file and it gave me no luck. the txt file in...
3
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is...
1
maliksleo
by: maliksleo | last post by:
hi i am using the following class for email sending but getting this error "Failure sending mail" Imports System.Net.Mail Public Class MailHelper ''' <summary> ''' Sends an mail...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.