hello I am working on html form submission via email. Server side scripting is P H P . my html form is
<form action='sendmail.php' method='post'>
Name:<input type="text" name="name">
File:<input type='file' name='attach'>
<input type="submit">
My php file for sending email is
<?php
$strTo = "xyz#gmail.com";
$strHeader .= "From: ".$_POST["name"]."<".$_POST["name"].">";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
if($_FILES["attach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = #mail($strTo,"no-subjet",null,$strHeader);
but its not going in if condition
Try replacing your form with this:
<form action="sendmail.php" method="post" enctype="multipart/form-data">
Name:<input type="text" name="name">
File:<input type="file" name="attach" id="attach">
<input type="submit">
</form>
The enctype attribute in the form is important.
See following link for more details:
http://www.w3schools.com/php/php_file_upload.asp
Also ensure all the names in PHP match with HTML, such as the name of file input is attach, so it should be the same in PHP.
if($_FILES["attach"]["name"] != "")
{
$strFilesName = $_FILES["attach"]["name"];
...
}
Related
This question already has answers here:
Send attachments with PHP Mail()?
(16 answers)
Closed 7 years ago.
I am trying to send attach file to email. But i am unable to send the attach file along with the form data to email. I tried
HTML:
<form action="sendmail.php" method="post" name="form1" enctype="multipart/form-data">
<table width="343" border="1">
<tr>
<td>Name</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>City</td>
<td><input name="city" type="text" id="city"></td>
</tr>
<tr>
<td>Descibe Yourself</td>
<td><textarea name="description" cols="30" rows="4" id="description"></textarea></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input name="mobile" id="mobile"type="text"></td>
</tr>
<tr>
<tr>
<td>Email</td>
<td><input name="email" type="email" id="email"></td>
</tr>
<tr>
<td>Attach Your Image</td>
<td><input name="fileAttach" type="file"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
sendmail.php:
<?
$name = $_POST['name'];
$city = $_POST['city'];
$description = $_POST['description'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
if ($name == '' || $city == '' || $description==''|| $mobile=='' || $email=='')
{
echo "<script> alert('Fill all fields, try again!');
window.location='contact.html'</script>";
exit;
}
$ToEmail = 'info#mywebsite.com';
$EmailSubject = 'Website contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br><br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Description: ".$_POST["description"]."<br>";
$MESSAGE_BODY .= "Mobile: ".nl2br($_POST["mobile"])."<br>";
$MESSAGE_BODY .= "City: ".nl2br($_POST["city"])."<br>";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader, $strHeader) or die ("Failure");
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
exit;
if($mail)
{
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
}
else
{
echo "<script> alert('Temporary problem, try again!');</script>";
}
?>
I tried the same code without $strHeader in mail() the mail was sent but when i added $strHeader to mail() i was unable to send code. Kindly guide me where i am doing mistake and also plz tell how how can i allow only jpg,jpeg,png format to to uploaded. Edited code for me would be easy for me for learning. I checked lot of answers on stackoverflow bt couldn't found the answer.
This has been already answered.
Check out form not sending image file to email
and my comment to send email with attachment.
Try using \r\n instead of \n ...
$strHeader .= "--".$strSid."\r\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\r\n";
$strHeader .= "Content-Transfer-Encoding: base64\r\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\r\n\r\n";
$strHeader .= $strContent."\r\n\r\n";
EDIT
Change:
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br><br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Description: ".$_POST["description"]."<br>";
$MESSAGE_BODY .= "Mobile: ".nl2br($_POST["mobile"])."<br>";
$MESSAGE_BODY .= "City: ".nl2br($_POST["city"])."<br>";
With:
$hash = md5(date('r', time()));
$mailheader = "From: {$_POST["email"]}\r\n";
$mailheader .= "Reply-To: {$_POST["email"]}\r\n";
$mailheader .= "Content-type: text/html; boundary=\"PHP-mixed-$hash\"";
$MESSAGE_BODY = "Name: {$_POST["name"]}<br><br>";
$MESSAGE_BODY .= "Email: {$_POST["email"]}<br>";
$MESSAGE_BODY .= "Description: {$_POST["description"]}<br>";
$MESSAGE_BODY .= "Mobile: ".nl2br($_POST["mobile"])."<br>";
$MESSAGE_BODY .= "City: ".nl2br($_POST["city"])."<br>";
And change
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
With
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$MESSAGE_BODY .= "--PHP-mixed-$hash\r\n";
$MESSAGE_BODY .= "Content-Type: application/octet-stream; name=\"$strFilesName\"\r\n";
$MESSAGE_BODY .= "Content-Transfer-Encoding: base64\r\n";
$MESSAGE_BODY .= "Content-Disposition: attachment; filename=\"$strFilesName\"\r\n\r\n";
$MESSAGE_BODY .= $strContent."\r\n";
$MESSAGE_BODY .= "--PHP-mixed-$hash--";
You missed the boundary.
<?php
//if there is post
if(isset($_POST) && !empty($_POST)){
//if there is attachment
if(!empty($_FILES['attachment']['name'])){
//store some variables
$file_name = $_FILES['attachment']['name'];
$temp_name = $_FILES['attachment']['tmp_name'];
$file_type = $_FILES['attachment']['type'];
//get the extension of the file
$base = basename($file_name);
$extension = substr($base, strlen($base)-4,strlen($base));
//only these file type will be allowed
$allow_extensions = array(".doc","docx",".pdf",".zip",".png");
//check if file is allowes
if(in_array($extension,$allow_extensions)){
//mail essentials
$from = $_POST['email'];
$to = "sampleemail#gmail.com";
$replyto = $to;
$subject = "email with attachment";
$message = "this is a random message";
//things you need
$file = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
//standard mail headers
$header = "From " . $from . "\r\n";
$header .= "Reply-To: " . $replyto . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
//declairing we hav e multiple parts of message like text
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format. \r\n";
//plain text part
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
//file attachment
$header .= "--".$uid."\r\n";
$header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content. "\r\n\r\n";
//send mail
if(mail($to, $subject, "", $header)){
echo "Mail Sent";
}
else
{
echo "Failed";
}
}
else{
echo "file type not allowed";
}
}
else{
echo "no file posted";
}
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="text" name="email" value="from" />
<br>
<input type="file" name="attachment" />
<br>
<input type="submit" value="Send Mail" />
</form>
</body>
</html>
Can't find the bug to my code, I am not getting the link to my attachment.. T_T please help. I am not good in boundary.. T_T I tried using phpmailer but can't get it to work, is there any document to read on how to set it up? I really just wanted to make a simple form with attach button for applicant to sent their resumes..
Everything after $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; should be in a $body, not a header.
I would get rid of this: $header .= "This is a multi-part message in MIME format. \r\n";
After $content you actually need to put another line with the mime separator.
$body .= $content . "\r\n" . '--' . $uid . '--';
And finally
if (mail($to, $subject, $body, $header)) {...
So basically I want an email system that can send a message with one or more pictures, the problem I have now is that when I upload let's say 4 pictures, the form sends me 4 emails with both the same text but one picture at a time. I want them all to be added as 4 attachments to 1 email, not 1 attachment to 4 emails.
Here is my HTML:
<form id="upload" method="post" action="upload.php">
<div id="drop">
Onderwerp<br>
<input name="txtSubject" type="text" id="txtSubject" /><br>
Omschrijving<br>
<textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea><br>
Voeg afbeeldingen toe
<input type="file" name="fileAttach" multiple accept="image/*;capture=camera" />
<input type="submit" name="Submit" value="Send">
</div>
<ul>
<!-- The file uploads will be shown here -->
</ul>
</form>
and here is my PHP:
<?
$strTo = "email#email.com";
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = #mail($strTo,$strSubject,null,$strHeader); // # = No Show Error //
if($flgSend)
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
?>
I'm not that great with PHP, I took an multiple image uploader and tried to make it into a mailing form, wich works.. except for the multiple email sending part.
Any help is greatly appreciated! :)
try something like:
for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++)
{
if($_FILES["fileAttach"]["name"][$i] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"][$i];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"][$i])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
}
I am making a PHP form which allow users to upload attachment and send it to my e-mail. I have been searching for quite a long time to make it.
And, finally, I found this. http://www.shotdev.com/php/php-mail/php-send-email-upload-form-attachment-file/. It works fine.
However, when I modify it myself (change the fields), something doesn't go well.
<?php
$location=$_POST['location'];
$name_ha=$_POST['name_ha'];
$name_person=$_POST['name_person'];
$email=$_POST['email'];
$date_sent=$_POST['date_sent'];
$date_completed=$_POST['date_completed'];
$date_received=$_POST['date_received'];
$to="admin#admin.com" . "$email";
$message="to";
//*** Uniqid Session ***//
$sid = md5(uniqid(time()));
$header = "";
$header .= "From: ".$_POST["name_ha"]."<".$_POST["email"].">\nReply-To: ".$_POST["email"]."";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$sid."\"\n\n";
$header .= "This is a multi-part message in MIME format.\n";
$header .= "--".$sid."\n";
$header .= "Content-type: text/html; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $message."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$FilesName = $_FILES["fileAttach"]["name"];
$Content = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$header .= "--".$sid."\n";
$header .= "Content-Type: application/octet-eam; name=\"".$FilesName."\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"".$FilesName."\"\n\n";
$header .= $Content."\n\n";
}
$flgSend = #mail($to,"A new file for you!",null,$header); // # = No Show Error //
if ($flgSend)
{
echo "Mail sent.";
}
?>
The files I downloaded from shotdev.com and the one I modified are being hosted on the same server and under the same folder.
But, for the one I have modified, the email is sent before the attachment is uploaded (~ 45% of the uploading process) if the file size is greater than 1MB. The email I received, there is no attachment and no information of sender ($name_ha).
On the other hand, for the files downloaded on shotdev.com, the email will only be sent after the attachment is uploaded completely no matter how big it is.
Is there any error of the script, or something is missing, causing such an occurrence? Your time and help is much appreciated.
First, in code that you showed as example you have error on this line:
$to="admin#admin.com" . "$email";
Change it to:
$to="admin#admin.com, " . "$email";
Notice comma that you are missing... It needed to be there for every new receivers email you want to add on that particular way...
Also I have tested code on my server, everything works well.
I have 100 mbps upload and tried file that is 4.5 MB and it works.
So maybe there is a problem with your upload speed and allowed execution time of php script that you are calling to send this email.
Try to add the following just after <?php in php file that you setted in HTML form as action="something.php":
set_time_limit(0);
That means that there is no liimt in execution time of script, change 0 to desired number of seconds...
Also remove # before #mail() function if there are errors you need to see them, hiding them will not do any good for you.
EDIT:
I have altered your code so that it does check if, firstly if there is file, if not sends mail without attachment. And if there is file it checks if it is encoded to base64 and splited and in that case it send the mail with attachment...
<?php
$location=$_POST['location'];
$name_ha=$_POST['name_ha'];
$name_person=$_POST['name_person'];
$email=$_POST['email'];
$date_sent=$_POST['date_sent'];
$date_completed=$_POST['date_completed'];
$date_received=$_POST['date_received'];
$FilesName = $_FILES["fileAttach"]["name"];
$to = "admin#mail.com," . "$email";
$message = "to";
$sid = md5(uniqid(time()));
$header = "";
$header .= "From: ".$_POST["name_ha"]."<".$_POST["email"].">\nReply-To: ".$_POST["email"]."";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$sid."\"\n\n";
$header .= "This is a multi-part message in MIME format.\n";
$header .= "--".$sid."\n";
$header .= "Content-type: text/html; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $message."\n\n";
if($_FILES["fileAttach"]["name"] != "") {
$Content = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$header .= "--".$sid."\n";
$header .= "Content-Type: application/octet-stream; name=\"".$FilesName."\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"".$FilesName."\"\n\n";
$header .= $Content."\n\n";
}
if (strlen($FilesName) > 0) {
if ($Content) {
$flgSend = mail($to,"Here is that file",null,$header);
}
else {
echo "problem with file...";
}
}
else {
$flgSend = mail($to,"Here is that file",null,$header);
}
if ($flgSend) {
echo "Mail sent.";
}
?>
HERE IS HTML FOR IT:
<html>
<head>
</head>
<body>
<form method="post" action="sender.php" enctype="multipart/form-data" >
location: <input type="text" name="location" />
<br />
name_ha: <input type="text" name="name_ha" />
<br />
name_person: <input type="text" name="name_person" />
<br />
email: <input type="text" name="email" />
<br />
date_sent: <input type="text" name="date_sent" />
<br />
date_completed: <input type="text" name="date_completed" />
<br />
date_received: <input type="text" name="date_received" />
<br />
file: <input type="file" name="fileAttach" />
<br />
<input type="submit" value="submit" />
</form>
</body>
</html>
This is the fourth time I'm asking this query.
I have a contact form, that I got from the Internet, with file attachment. It's showing no error but when I tried to send mail with a file attached it didn't work. Can you tell me what is the problem or can you suggest a good simple contact form with file attachment? I already tried most contact forms with file attachment on the Internet but the file attachment part in most does not work.
Below is a small part of the HTML code that is part of my script. My site is online and because of this I'm facing problems.
<form action="" method="post" name="form1" enctype="multipart/form-data">
<input name="txtTo" type="text" id="txtTo">
<input name="txtSubject" type="text" id="txtSubject">
<textarea name="txtDescription" cols="30" rows="4" id="txtDescription">
<input name="txtFormName" type="text">
<input name="txtFormEmail" type="text">
<input name="fileAttach" type="file">
<input type="submit" name="Submit" value="Send">
</form>
php script
<?php
if(isset($_POST["submit"])){
$strTo = $_POST["txtTo"];
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"] ["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = #mail($strTo,$strSubject,null,$strHeader); // # = No Show Error //
if($flgSend)
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
}
?>
This is my humble answer. I formatted your code a little and created a stand-alone version of it (with some simple styling^^).
Live demo: http://kopli.pri.ee/stackoverflow/6935517.php
(Please don't abuse my little mail-sending service)
In a nutshell it seems, that the $_POST["submit"] was the main issue. However, it is possible, that I fixed some other critical aspect and forgot to note it out.
NOTE: Maybe your script worked in some ways, but your e-mails providers anti-spam systems marked it as spam?! Also, if your page was not correctly encoded, then there might have been conflicts with the UTF-8 format of the email...
I would wish to give some pointers to you:
There was a critical problem with $_POST["submit"], no such input in the form.. meaning its not a valid trigger
Your <textarea> was not closed and was causing problems.
I'm using xhtml in my example, so <input>'s need to be ended with /
In <input> for PHP, you don't need have id="txtSubject" (id's are useful when dealing with JS)
There is no point of having name="" in <form>
There were some weird spaces in your PHP code. Example: $_FILES["fileAttach"] ["tmp_name"]. That's not very correct code!
Adding . "" at the end of a string is very much pointless
Full standalone code:
<?php
if (isset($_POST["submit_trigger"])) {
$strTo = $_POST["txtTo"];
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: " . $_POST["txtFormName"] . "<" . $_POST["txtFormEmail"] . ">\nReply-To: " . $_POST["txtFormEmail"];
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"" . $strSid . "\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--" . $strSid . "\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage . "\n\n";
//*** Attachment ***//
if ($_FILES["fileAttach"]["name"] != "") {
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--" . $strSid . "\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"" . $strFilesName . "\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"" . $strFilesName . "\"\n\n";
$strHeader .= $strContent."\n\n";
}
// # = No Show Error //
$flgSend = #mail($strTo, $strSubject, null, $strHeader);
if ($flgSend) {
$posting_message = '<div class="success_message">Mail send completed :)</div>';
} else {
$posting_message = '<div class="error_message">Cannot send mail :(</div>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Can you tell me what is the problem with this script - Kalle H. Väravas</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
html, body {margin: 0px; padding: 0px; background: #B3D9FF;}
label {font-weight: bold; width: 140px; display: inline-block; padding: 10px;}
.success_message,
.error_message {display: inline-block; padding: 2px 5px; font-weight: bold; margin-bottom: 5px;}
.success_message {background: #A9F5AB;}
.error_message {background: #FF8080;}
#main_container {width: 500px; -moz-border-radius: 5px; background: #FFFFFF; margin: 20px auto; padding: 20px;}
</style>
</head>
<body>
<div id="main_container">
<?php echo $posting_message; ?>
<form action="" method="post" enctype="multipart/form-data">
<input name="submit_trigger" value="1" type="hidden" />
<label>To:</label><input name="txtTo" type="text" /><br />
<label>Subject:</label><input name="txtSubject" type="text" /><br />
<label>Message:</label><textarea name="txtDescription" cols="30" rows="4"></textarea><br />
<label>From name:</label><input name="txtFormName" type="text" /><br />
<label>From email</label><input name="txtFormEmail" type="text" /><br />
<label>Attachment:</label><input name="fileAttach" type="file" /><br />
<input type="submit" name="Submit" value="Send" /><br />
</form>
</div>
</body>
</html>
file name = "php_sendmail_upload1"
<form action="#" method="post" name="form1" class="blocks" enctype="multipart/form-data" class="blocks">
<p>
<label>Name</label>
<input name="txtFormName" class="text" type="text">
</p>
<p>
<label>Email</label>
<input name="txtFormEmail" type="text" class="text">
</p>
<p>
<label>Position Applying For</label>
<input type="text" name="txtDescription" id="txtDescription" class="text">
</p>
<p class="area">
<label>Upload CV</label>
<input name="fileAttach" type="file" >
</p>
<p>
<label> </label>
<input type="submit" class="submit" name="Submit" value="SEND" />
</p>
</form>
<?
$strTo = "info#mysticsadvertising.com";
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = #mail($strTo,$strSubject,null,$strHeader); // # = No Show Error //
if($flgSend)
{
echo "";
}
else
{
echo "Cannot send mail.";
}
?>
file name="php_sendmail_upload2"
<?
$strTo = "info#xxxxxx.com";
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = #mail($strTo,$strSubject,null,$strHeader); // # = No Show Error //
if($flgSend)
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
?>