Hi, anyone? i tried this on my server but the attachment i tried to send with my form mail does not comes in base64 which should turn out to be a file instead of a string of codes inside the mail. thanks everyone in advance.
<?php $email = $_REQUEST['email']; $message = $_REQUEST['message']; $msg = $_REQUEST['msg']; $subject = $_REQUEST['subject']; $coname = $_REQUEST['coname']; $user = $_REQUEST['user']; $reg = $_REQUEST['reg']; $ctc = $_REQUEST['ctc']; $xbrldoc = $_REQUEST['xbrldoc']; $doc = $_REQUEST['doc']; $ver = $_REQUEST['ver']; $dnt = $_REQUEST['dnt']; $agent = $_REQUEST['agent']; $attachment = $_FILES['attachment']['tmp_name']; $attachment_name = $_FILES['attachment']['name']; if (is_uploaded_file($attachment)) { //Do we have a file uploaded? $fp = fopen($attachment, \"rb\"); //Open it $data = fread($fp, filesize($attachment)); //Read it $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed fclose($fp); } mail( \"to@mail.com\", \"$subject\", \"Hi Daniel, \n\nProblem Description: $msg \n\n\n\nUser's Name: $user \nCo Regn No: $reg \nCompany Name: $coname \nContact No: $ctc \nEmail Address: \n\n\nXBRL Document: $xbrldoc \nText Source Document: $doc \nWeb Browser Version: $ver \nDate/Time Error occured: $dnt \n\n\n\n\nRegards,\n$agent \nHelpdesk \n$data\", \"From: me@mail.com\"); header( \"Location: thankyou.htm\" ); ?>
Using the script provided (1st page), I am able to send emails with attachments and I get the email and attachment intact. However, no body (no message!) shows up on webmail OR Pop3 when I check it.
This is stock script with minimal modifications. Has anyone experienced this?.. or know of a work-around?
Like I said, its pretty stock. After grabbing it and modifying it didnt work... I kept deleting my modifactions all the way back until I have damn nearly the exact file I pulled from the post on page 1. I upload it, populate, send, it works and sends emails just no body-text output at all.
Basically, just a static from and a static to email address. Being used as a basic contact form with resume attachment.
Noticed a couple other people had the same problem earlier on in the thread but never seemed to have gotten a reply.
[html]
PHP Code: <?php</font> /* Mailer with Attachments */ $action = $_REQUEST['action']; global $action; function showForm() { ?> " method=post encType=multipart/form-data>
if ($ok == 1) { print "Mail sent to $to_name ($to_email)."; } else { print "Mail did not send. Please press the back button and re-submit the e-mail."; } } ?>
So you do receive the email, but there's nothing in the body? Does the subject show?
Paste the code you're using inside [ php ] [ /php ] tags (don't have the spaces)
Its odd. Tested using outlook 2003 AND webmail. Problem is the same, regarless.
I installed the same script on two remote hosting sites. My godaddy hosting runs it perfectly. The other no-name fischer-price webhost is the one I have the problems with, so I am sure its not the script's fault. The email from the problematic host shows a working attachment, but no message is displayed.
So I've given up on it. Unless you know a work around. Similarly, I'll end up remote hosting the script and cross linking to it. But i need to work out a redirect to get me back to the origonal site after the script runs.
BTW, Im running Kwitko's script pretty much stock (shown partially above). Again, I'm fing out now I think the hosting is just cheap. Script is verified worker elsehwere for me.
hello....mr [B]Kwitko can you pls help me..ur code works very fine..but i need to attach multiple files....and i try to use foreach...but i cant get the right one..am lost...could u pls show me the code..pls?tnx [/B]
hello....mr [B]Kwitko can you pls help me..ur code works very fine..but i need to attach multiple files....and i try to use foreach...but i cant get the right one..am lost...could u pls show me the code..pls?tnx [/B]
That functionality was added some time back. Look through this thread again and you'll see the code for it.
Very new to php and have tried this script and had no success so after messing around with it and some other basic forms i have come up with a script that somewhat works. As of right now i can get it to send the e-mail but the attachment is showing up in the body area of the email and is showing up as what i am guessing to be the base 64 code as it looks like this
$emailadd = 'me@mymail.com'; $url = 'http://www.mydomain.com/confirmation.htm'; $req = '1'; $attachment = $_FILES['attachment']['tmp_name']; $attachment_name = $_FILES['attachment']['name']; if (is_uploaded_file($attachment)) { //Do we have a file uploaded? $fp = fopen($attachment, \"rb\"); //Open it $data = fread($fp, filesize($attachment)); //Read it $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed fclose($fp); } mail($emailadd, $message, $data); echo '****** HTTP-EQUIV=Refresh CONTENT=\"0; URL='.$url.'\">'; ?>
any help with this would be great and I would like to extend my thanks in advance.
As promised. Now I didn't add any error checking or formatting. My goal was simply to make sure the MIME encoding was done right. MIME headers are *very* finicky. If you want to add more attachments, you could foreach or while the chunk routine.
Without further ado, I give you:
[code] //EDIT: added some additional comments. I realized after posting that it's kind of silly to add the MIME boundary if you're not neccessarily sending an attachment, so the encoding routine plus the boundaries for the attachment should really be conditional. Then again, the whole purpose of this script is so you can send attachments, right?
here is a better upgrade with error checking or formatting to your upload form and mime headers. requires little php and html knowledge
---enjoy
=============================================
<?php $fileatt = ""; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = ""; // Filename that will be used for the file as the attachment $email_from = ""; // Who the email is from $email_subject = ""; // The Subject of the email $email_txt = ""; // Message that the email has in it $email_to = ""; // Who the email is too $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; $ok = @mail($email_to, $email_subject, $email_message, $headers); if($ok) { echo "<font face="verdana">The file was successfully sent!"; } else { die("Sorry but the email could not be sent. Please go back and try again!"); } ?>
Hello all, I won't hold my breath waiting for a reply on a 6 month old thread, but if anyone sees this and can offer some help, it would be very much appreciated!
I've used the original code, and modified it to have 5 slots for attachments... It works perfectly when either 4 or 5 attachments are included, but if fewer than 4 are attached, it doesn't send. It prints out the 'Mail sent' message, but no email actually arrives.
I originally tried using the dynamic javascript code to allow users to attach as many files as they would like, but that didn't work out too well as I have very minimal experience with javascript. I was then told that users can't be able to submit more than 5 files anyway, so abandoned that idea.
$body= \" Practice Name: $PracticeName Dr Name: $DrName Address: $Street, $City, $Province, $PostalCode Phone: $Phone Fax: $Fax Email: $from_email Website: $Website Hours of Operation:
Sunday: $SunFrom to $SunTo $ClosedSun Monday: $MonFrom to $MonTo $ClosedMon Tuesday: $TuesFrom to $TuesTo $ClosedTues Wednesday: $WedFrom to $WedTo $ClosedWed Thursday: $ThursFrom to $ThursTo $ClosedThurs Friday: $FriFrom to $FriTo $ClosedFri Saturday: $SatFrom to $SatTo $ClosedSat \";
$subject= \"Membership Profile Form\";
$filecount = 0; foreach($_FILES as $file => $value) { $attachment[(int)$filecount] = $_FILES[$file]['tmp_name']; $attachment_name[(int)$filecount] = $_FILES[$file]['name']; if (is_uploaded_file($attachment[(int)$filecount])) { //Do we have a file uploaded? $fp = fopen($attachment[(int)$filecount], \"rb\"); //Open it $data[(int)$filecount] = fread($fp, filesize($attachment[(int)$filecount])); //Read it $data[(int)$filecount] = chunk_split(base64_encode($data[(int)$filecount])); //Chunk it up and encode it as base64 so it can emailed fclose($fp); $filecount++; } }
Essentially, I just need users to be able to send any number of attachments between 0 and 5. This is the first time I've worked with headers and attachments and the like, so forgive me if the solution is obvious!
Thanks in advance for any assistance anyone can offer.
Lincoln
Snapperhead Admin, Supporter, Expo Attendee
Are you able to turn on error reporting? The easiest first step in a debug is always to see what sort of Notices or Warnings might be cropping up.
I'm going to go out on a limb and say it's something wrong with the foreach($_FILES as $file => $value) loop. I don't know if blindly looping through the $_FILES element like that is a good idea. The only way I've done it is to individually check each possible expected field ($_FILES['attachement'], $_FILES['attachment2'], etc) and go from there.
If it wigs out from 3 or less, I'd say that when it finds a second empty file field in the loop it's running into an error. That's my best intuitive guess from your description of the problem, anyway.
Thanks, Lincoln! I couldn't get error checking turned on, but I tried separating the foreach loops into 5 individual sections and that seemed to do the trick! Much appreciated. :)
Q1. How do you get the original script to work with sending to multiple email addresses (multiple recipients)?
Q2. A follow up to Q1, how can the script be adjusted so that only the "username" is required and the email sent would go to the username's account with Yahoo, Gmail, etc... as in below. One would only enter the username in the to_email field and the mailer would send emails to all the listed addresses in the array for that username. $username = 'to_ recipient'; $to_email = array('to_ [email]recipient@yahoo.com[/email]', 'to_ [email]recipient@gmail.com[/email]');
Sorry if the syntax is wrong since I am a PHP/JS newbie. Any help would be greatly appreciated. Thanks much in advance.
1) I'm going to go out on a limb and say use a comma separated list i.e. ("a@ randomdomainhere.com", "b@randomdomainhere.com")
2) You'd likely want to do one of two things, have an open dataset/array that has all of the recipients information (email, name, etc) although I'm not all THAT familiar with php at this moment. The other option is to build a multi-dimensional array of [username][email] to loop through. Personally, I'd use the unique ID of the user and not the name...otherwise you can run into some stupid stuff happening.
Comments
anyone? i tried this on my server but the attachment i tried to send with my form mail does not comes in base64 which should turn out to be a file instead of a string of codes inside the mail.
thanks everyone in advance.
I was wondering if someone could help me out.
Using the script provided (1st page), I am able to send emails with attachments and I get the email and attachment intact. However, no body (no message!) shows up on webmail OR Pop3 when I check it.
This is stock script with minimal modifications. Has anyone experienced this?.. or know of a work-around?
Basically, just a static from and a static to email address. Being used as a basic contact form with resume attachment.
Noticed a couple other people had the same problem earlier on in the thread but never seemed to have gotten a reply.
[html]
PHP Code:
<?php</font>
/* Mailer with Attachments */
$action = $_REQUEST['action'];
global $action;
function showForm() {
?>
" method=post encType=multipart/form-data>
Name:
Email:
Subject:
Message:
Attachment:
<?php</font>
}
function sendMail() {
$to_name = "";
$from_name = stripslashes($_POST['name']);
$subject = stripslashes($_POST['subject']);
$body = stripslashes($_POST['body']);
$to_email = "williamschott@comcast.net";
$from_email = stripslashes($_POST['from_email']);
$phone = stripslashes($_POST['phone']);
//Let's start our headers
$headers = "From: $from_name <" . $_POST['from_email'] . ">\n";
$headers .= "Reply-To: <" . $_POST['from_email'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
$headers .= "X-Sender: $from_name <" . $_POST['from_email'] . ">\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
$headers .= "Return-Path: <" . $_POST['from_email'] . ">\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDRY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
$message = "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= "$body\n";
$message .= "\n";
$message .= "------=MIME_BOUNDRY_message_parts--\n";
$message .= "\n";
foreach($_FILES as $file => $value) {
$_tmpname = $_FILES[$file]['tmp_name'];
$_filename = $_FILES[$file]['name'];
if (is_uploaded_file($_tmpname)) { //Do we have a file uploaded?
$fp = fopen($_tmpname, "rb"); //Open it
$data = fread($fp, filesize($_tmpname)); //Read it
$data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
$message .= "------=MIME_BOUNDRY_main_message\n";
$message .= "Content-Type: application/octet-stream;\n\tname=\"" . $_filename . "\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"" . $_filename . "\"\n\n";
$message .= $data; //The base64 encoded message
$message .= "\n\n";
fclose($fp);
}
}
$message .= "------=MIME_BOUNDRY_main_message--\n";
// send the message
$ok = mail("$to_name <$to_email>", $subject, $body, $headers);
if ($ok == 1) {
print "Mail sent to $to_name ($to_email).";
} else {
print "Mail did not send. Please press the back button and re-submit the e-mail.";
}
}
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php</font>
switch ($action) {
case "send":
sendMail();
showForm();
break;
default:
showForm();
}
?>
[/html]
cause i m also using same, but nothing for the attacment
can u explain?
tks
Paste the code you're using inside [ php ] [ /php ] tags (don't have the spaces)
Its odd. Tested using outlook 2003 AND webmail. Problem is the same, regarless.
I installed the same script on two remote hosting sites. My godaddy hosting runs it perfectly. The other no-name fischer-price webhost is the one I have the problems with, so I am sure its not the script's fault. The email from the problematic host shows a working attachment, but no message is displayed.
So I've given up on it. Unless you know a work around.
Similarly, I'll end up remote hosting the script and cross linking to it. But i need to work out a redirect to get me back to the origonal site after the script runs.
header( "Location: [EMAIL="back@mysiteafterscriptruns.com"]back@mysiteafterscriptruns.com[/EMAIL]" );
craps out.
BTW, Im running Kwitko's script pretty much stock (shown partially above). Again, I'm fing out now I think the hosting is just cheap. Script is verified worker elsehwere for me.
form in html:
[html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Form2Mail
****** http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
[/html]
here goes the php:
Uploaded to my site, the script runs perfectly. Uploaded to client's site, the email craps out and arrives w/ attachment and no message.
So I know the code is correct.
[/B]
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
Ly9FTiINImh0dHA6Ly93d3cudzMub3JnL1RSL2h0bWw0L2xvb3NlLmR0ZCI+DTxodG1sPg08aGVh
ZD4NPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNo
YXJzZXQ9aXNvLTg4NTktMSI+DTx0aXRsZT5Bbm5lJ3MgUmVudGFsczwvdGl0bGU+DTxzdHlsZSB0
eXBlPSJ0ZXh0L2NzcyI+DTwhLS0NLnN0eWxlMSB7DQlmb250LWZhbWlseTogVmVyZGFuYSwgQXJp
YWwsIEhlbHZldGljYSwgc2Fucy1zZXJpZjsNCWZvbnQtc2l6ZTogMjRweDsNfQ0uc3R5bGUyIHsN
CWZvbnQtc2l6ZTogMTJweDsNCWZvbnQtZmFtaWx5OiBWZXJkYW5hLCBBcmlhbCwgSGVsdmV0aWNh
the code i am using is as follows:
here is a better upgrade with error checking or formatting to your upload form and mime headers. requires little php and html knowledge
---enjoy
=============================================
<?php
$fileatt = ""; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = ""; // Filename that will be used for the file as the attachment
$email_from = ""; // Who the email is from
$email_subject = ""; // The Subject of the email
$email_txt = ""; // Message that the email has in it
$email_to = ""; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<font face="verdana">The file was successfully sent!";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
http://phpmailer.codeworxtech.com/
I use it every time I need to send attachments.
I won't hold my breath waiting for a reply on a 6 month old thread, but if anyone sees this and can offer some help, it would be very much appreciated!
I've used the original code, and modified it to have 5 slots for attachments... It works perfectly when either 4 or 5 attachments are included, but if fewer than 4 are attached, it doesn't send. It prints out the 'Mail sent' message, but no email actually arrives.
I originally tried using the dynamic javascript code to allow users to attach as many files as they would like, but that didn't work out too well as I have very minimal experience with javascript. I was then told that users can't be able to submit more than 5 files anyway, so abandoned that idea.
This is the file with the form:
[HTML]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
****** http-equiv="Content-Type" content="text/html; charset=utf-8" />
The Alliance of Dental Care Professionals******** type="text/javascript">
******** src="scripts/AC_RunActiveContent.js" type="text/javascript">
Profile
[/HTML]
and this is the formproc.php file:
Essentially, I just need users to be able to send any number of attachments between 0 and 5. This is the first time I've worked with headers and attachments and the like, so forgive me if the solution is obvious!
Thanks in advance for any assistance anyone can offer.
I'm going to go out on a limb and say it's something wrong with the foreach($_FILES as $file => $value) loop. I don't know if blindly looping through the $_FILES element like that is a good idea. The only way I've done it is to individually check each possible expected field ($_FILES['attachement'], $_FILES['attachment2'], etc) and go from there.
If it wigs out from 3 or less, I'd say that when it finds a second empty file field in the loop it's running into an error. That's my best intuitive guess from your description of the problem, anyway.
Q2. A follow up to Q1, how can the script be adjusted so that only the "username" is required and the email sent would go to the username's account with Yahoo, Gmail, etc... as in below. One would only enter the username in the to_email field and the mailer would send emails to all the listed addresses in the array for that username.
$username = 'to_ recipient';
$to_email = array('to_ [email]recipient@yahoo.com[/email]', 'to_ [email]recipient@gmail.com[/email]');
Sorry if the syntax is wrong since I am a PHP/JS newbie. Any help would be greatly appreciated. Thanks much in advance.
2) You'd likely want to do one of two things, have an open dataset/array that has all of the recipients information (email, name, etc) although I'm not all THAT familiar with php at this moment. The other option is to build a multi-dimensional array of [username][email] to loop through. Personally, I'd use the unique ID of the user and not the name...otherwise you can run into some stupid stuff happening.
$username = 'to_ recipient';
$to_email = array( $username.'@yahoo.com', $username.'@gmail.com');