Unable to send attached file to E-Mail [duplicate] - php

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.

Related

mail function not working properly

Can someone please help me with my mail function issue.
I want to receive text values in table and an attachment. Right now I am receiving the table code instead of the code output and the attachment.
And If I delete the modification I made for the attachment then I get the right output but only text.
<?php
include("config.php");
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$fn1 = $_POST['fn1'];
$fn2 = $_POST['fn2'];
$fn3 = $_POST['fn3'];
$fn4 = $_POST['fn4'];
$fn28= $_POST['fn28'];
$subject = 'test';
//get file details we need
$file_tmp_name = $_FILES['fn28']['tmp_name'];
$file_name = $_FILES['fn28']['name'];
$file_size = $_FILES['fn28']['size'];
$file_type = $_FILES['fn28']['type'];
$file_error = $_FILES['fn28']['error'];
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("vikas");
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$email."\r\n";
$headers .= "Reply-To: ".$email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
$msg = "
<table border='1'>
<tbody>
<th>
<td><h3>Contact Information</h3></td>
</th>
<tr>
<td><b>Borrower's Full Name</b></td>
<td><span style='color:#F34536;'> $firstname $lastname </span></td>
</tr>
<tr>
<td><b>Email</b></td>
<td><span style='color:#F34536;'> $email</span></td>
</tr>
<tr>
<td><b>Attach Key Documents (optional)</b></td>
<td><span style='color:#F34536;'> $fn28</span></td>
</tr>
</tbody>
</table>
";
$msg1 = chunk_split(base64_encode($msg));
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= $msg1;
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
mail($toemail, $subject, $body, $headers)
?>
Is because you have this line:
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
All code is sent in text-plain, delete it and change it as text/html in $header:
$header .= 'MIME-Version: 1.0\r\n';
$header .= 'Content-type: text/html; charset=iso-8859-1\r\n';

Email form sends multiple mails depending on attachments

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";
}
}

Contact form throws errors when sending an email.

I am developing a contact form for sending an email to user data,but its not working.
Code:
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'youremail#site.com';
$EmailSubject = 'Site 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"]."";
$MESSAGE_BODY = "Email: ".$_POST["email"]."";
$MESSAGE_BODY = "Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Your message was sent
<?php
} else {
?>
<form action="mail.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="Comment" cols="45" rows="6" id="Comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php
};
?>
It throws an errors like:
Undefined index: commen in line 10.
header missing in line 11.
Here are some mistakes on your code..
1.at the line no 2 change the code from (i don't know why you didn't mention about this error)
if ($_POST["email"]<>'') {
to
if (isset($_POST["email"]) && $_POST["email"]<>'') {
2.change the name of the textarea from "Comment" to "comment"
and finally follow the instruction from the previous answers of this post to solve the "header missing" problem.
something like
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
As everybody told your first mistake, I am not going to repeat it but another mistake is:
You should join the mail headers and mail body:
Your previous code:
$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"]."";
$MESSAGE_BODY = "Email: ".$_POST["email"]."";
$MESSAGE_BODY = "Comment: ".nl2br($_POST["comment"])."";
New Code:
$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"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
Look at the dots given before the equalto signs.
see you need to concatenate the mailHeader var same goes for body message
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
You have done the two mistakes.
In form you have given name="Comment" for please give name="comment" or $_POST["comment"] to $_POST["Comment"]
put the . after mail header.like
$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"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
you are getting this error 10th line because you are using $_POST["comment"]" but in the form you have written id="Comment". To remove the error take care of upar and lower case in the both places..
Thank you.

file attachment mail in php

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"];
...
}

What is the problem with this script?

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.";
}
?>

Categories