Jump to content

PHP ATTACMENT PROBLEM


mrelusive

Recommended Posts

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, nidvanitri@msn.com";

 

 

$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!");}

 

 

?>

Link to comment
Share on other sites

$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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

You see my script on the beginig.

I found another script that sending attachment

<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//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: webmaster@example.com\r\nReply-To: webmaster@example.com";
//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.

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.