473,396 Members | 2,108 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,396 software developers and data experts.

Php code sending 2 mail with attachment - Please help

1
<?php

ini_set('error_reporting', E_NONE);

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
//Read POST request params into global vars
$to = "xyz@gmail.com";
$from = "info@rubiksol.in";
$subject = "New Resume";
$message_to_send = "Please find the attachment";

if (isset($_FILES["attachment_file"]) && $_FILES['attachment_file']['name'] != "")
{
// Obtain file upload vars
$attachment_file = $_FILES['attachment_file']['tmp_name'];
$attachment_file_type = $_FILES['attachment_file']['type'];
$attachment_file_name = $_FILES['attachment_file']['name'];

$name = $_FILES['attachment_file']['name'];
$size = $_FILES['attachment_file']['size'];

//Allowed file types - You may specify more if you wish
$allowedExtensions = array("jpg","jpeg", "gif","png","doc","docx","txt","rtf","pdf","zi p");
$attached_file_extension = pathinfo($name, PATHINFO_EXTENSION);

//$attached_file_extension = end(explode(".", $name)); You can still use this instead if you wish

function isAllowedExtension($attachmentFile)
{
global $allowedExtensions;
global $attached_file_extension;
return in_array($attached_file_extension, $allowedExtensions);
}

if (!isAllowedExtension($_FILES['attachment_file']['name']) )
{
echo '<br clear="all" /><div class="info" align="left">Sorry, you attached an invalid file type. <br>We only accept jpg, jpeg, gif, png, doc, docx, txt, rtf, pdf and zip files. Thanks.</div>';
}
else
{
if($size<(1024*1024))
{
$headers = "From: $from";

if (is_uploaded_file($attachment_file))
{
// Read the file to be attached ('rb' = read binary)
$file = fopen($attachment_file,'rb');
$data = fread($file,filesize($attachment_file));
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message_to_send . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$attachment_file_type};\n" .
" name=\"{$attachment_file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$attachment_file_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
$vasplus_mailer_delivers_greatly = @mail($to, $subject, $message, $headers);

if ($vasplus_mailer_delivers_greatly)
{
echo '<font style="font-size:0px;">vpb_sent&</font>';
echo "<br clear='all' /><div align='left' class='info'>Done successfully! Thanks.</div>";
}
else
{
echo "<br clear='all' /><div align='left' class='info'>Sorry, your email could not be sent at the moment. Please try again or contact this website admin to report this error message if the problem persist (1). Thanks.</div>";
}
}
else
{
echo "<br clear='all' /><div class='info' align='left'>File exceeded 1MB max allowed file size. <br>Please upload a file at 1MB in size to proceed. Thanks.</div>";
}

}
}
//Else if the user did not attach a file above, then proceed with the email sending below - (we will send a HTML type of Email instead)
else
{

}
}
?>
Aug 18 '17 #1
0 1409

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

Similar topics

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...
1
by: vinodkus | last post by:
dear sir/madam I m developing a program for mail attacment but i got an error error '80004005' /mail1.asp, line 24 . Please help me. <% Set newmail = server.CreateObject ("cdonts.newmail")...
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
by: dilip1076 | last post by:
I developed an application to send mail using smtpClient. my mail server is mail.brm.edu.in. I am passing this as "smtp.mail.brm.edu.in" but i'm unable to send. It shows failure sending mail. plz...
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: TanuLamba15 | last post by:
Hi All, Can anyone guide me I want to send attachment with my mail and I'm using http://demo.tutorialzine.com/2013/05/mini-ajax-file-upload-form/ plugin instead of simple <input type="file"/>, the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.