mrelusive Posted June 24, 2011 Share Posted June 24, 2011 Hy everyone, i found lot of code in the internet for sending mail with attachment, but i not sucsed to make it to work. Here is my code and if someone can help me i will bi thankefull to him. <?php $userName=$_POST["userName"]; $userEmail=$_POST["userEmail"]; $userComments=$_POST["userComments"]; $userAddress=$_POST["userAddress"]; $userPhone=$_POST["userPhone"]; $itemList=$_POST["itemList"]; $totalItems=$_POST["totalItems"]; $totalPrice=$_POST["totalPrice"]; $MailTo = "$userEmail, [email protected]"; $Subject = "Poruka"; $Body = "<font size=5><font color=#0066FF><b><u>Lista elemenata koriscenih u planeru</u>: </b></font></font><br><br><font size=2><B><font color=#0066FF>Od: </font></B>$userName<BR><font size=2><B><font color=#0066FF>Address: </font></B>$userAddress<BR><B><font color=#0066FF>Telefon: </font></B>$userPhone<BR><font size=2><B><font color=#0066FF>Email: </font></B><A HREF=mailto:$userEmail>$userEmail</A><BR><BR><B><font color=#0066FF>Elementi: </font></B><BR>$itemList<BR><BR><BR><B><font color=#0066FF>Ukupno elemenata: </font></B>$totalItems<BR><B><font color=#0066FF>Ukupna cena: </font></B>$totalPrice<BR><BR><B><font color=#0066FF>Komentar korisnika: </font></B>$userComments<BR>"; $headers = "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: Online planer"; $sendMail = mail($MailTo, "$Subject", "$Body", "$headers"); if(sendMail) { echo ("&mailSent=USPELO!");} else { echo ("&mailSent=NEUSPELO!");} ?> Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/ Share on other sites More sharing options...
mrelusive Posted June 27, 2011 Author Share Posted June 27, 2011 Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1235308 Share on other sites More sharing options...
EdwinPaul Posted June 27, 2011 Share Posted June 27, 2011 $sendMail = mail($MailTo, "$Subject", "$Body", "$headers"); if(sendMail) { echo ("&mailSent=USPELO!");} else { echo ("&mailSent=NEUSPELO!");} should be: <?php if(mail($MailTo, $Subject, $Body, $headers)) { echo ("USPELO!"); }else{ echo ("NEUSPELO!"); } ?> - Try to make the name of your variables with NO CAPITALS. It may confuse you later - Many mail-programs do not accept html-coding in messages. If possible, avoid it. - there are free email-packages on the internet for email with attachments. Try Libmail. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1235316 Share on other sites More sharing options...
mrelusive Posted June 27, 2011 Author Share Posted June 27, 2011 My code works good. I need someone to help me to add attachment into my code. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1235342 Share on other sites More sharing options...
EdwinPaul Posted June 27, 2011 Share Posted June 27, 2011 google: "php mail attachment" gives you links enough. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1235363 Share on other sites More sharing options...
mrelusive Posted June 27, 2011 Author Share Posted June 27, 2011 I know, and i was googling, and found script that work too. But i couldn't make my script and that or any other script to work together, because my script is taking data from sfw file and setup to do that. I need someone to help me to make my script to send attachment. Attachment is one file and always one file like attach.png for example. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1235372 Share on other sites More sharing options...
mrelusive Posted June 28, 2011 Author Share Posted June 28, 2011 Is it possible that no one can't help? Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1235785 Share on other sites More sharing options...
mrelusive Posted June 29, 2011 Author Share Posted June 29, 2011 HELP HELP HELP Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1236436 Share on other sites More sharing options...
EdwinPaul Posted June 29, 2011 Share Posted June 29, 2011 If you post you complete script, and explain what you tried with no success, maybe someone can tel you why it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1236446 Share on other sites More sharing options...
xyph Posted June 29, 2011 Share Posted June 29, 2011 Hire a programmer Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1236455 Share on other sites More sharing options...
mrelusive Posted June 29, 2011 Author Share Posted June 29, 2011 You see my script on the beginig. I found another script that sending attachment <?php //define the receiver of the email $to = '[email protected]'; //define the subject of the email $subject = 'Test email with attachment'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: [email protected]\r\nReply-To: [email protected]"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/zip; name="attachment.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> My script at begining in this lines read data from swf: $userName=$_POST["userName"]; $userEmail=$_POST["userEmail"]; $userComments=$_POST["userComments"]; $userAddress=$_POST["userAddress"]; $userPhone=$_POST["userPhone"]; $itemList=$_POST["itemList"]; $totalItems=$_POST["totalItems"]; $totalPrice=$_POST["totalPrice"]; My script work fine but not sending attachment. Attachment will be file attachment.png for example and will be on the server, no upload need. I am trying to add this lines from my script and line with $body in second script but no lacky every time some problem. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1236491 Share on other sites More sharing options...
EdwinPaul Posted June 29, 2011 Share Posted June 29, 2011 You see my script on the beginig. I found another script that sending attachment So this is NOT the script that doesn't work. I am trying to add this lines from my script and line with $body in second script but no lacky every time some problem. I still don't know what the problem is. No error messages? Put this at the beginning of your script and start debugging. <?php ini_set('display_errors',1); error_reporting(E_ALL | E_STRICT); ?> "My script work fine but not sending attachment." Why don't you use a normal package like PHPMailer or Libmail ? That is very easy and it works! Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1236511 Share on other sites More sharing options...
mrelusive Posted June 29, 2011 Author Share Posted June 29, 2011 Both script work fine separately. I am not programer, the man who wrote my script is not available any more. I don't know anything about PHPMailer or Libmail. My script only need to have attachment. I can't use other script without my script because they don't sending to mail input from my swf file. Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1236558 Share on other sites More sharing options...
mrelusive Posted July 1, 2011 Author Share Posted July 1, 2011 never mind forget i ask. By Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1237277 Share on other sites More sharing options...
The Little Guy Posted July 1, 2011 Share Posted July 1, 2011 http://phpsnips.com/snippet.php?id=112 Quote Link to comment https://forums.phpfreaks.com/topic/240319-php-attacment-problem/#findComment-1237290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.