Pomagajte ljudi ako boga znate. Evo nekoliko dana pokusavam ovo da resim i nikako da uspem.
Sve mislim da je probelm u Content-Type, ali nikako da resim.
Evo koda koji salje uspesno attachemnt:
Code:<?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";
?>
Moj kod:
Code:<?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>neki text</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: nesto nebitno";
$sendMail = mail($MailTo, "$Subject", "$Body", "$headers");
if(sendMail) {
echo ("&mailSent=USPELO!");}
else {
echo ("&mailSent=NEUSPELO!");}
?>
Na pocetku mog koda ovo cita podatke iz swf fajla
$userName=$_POST["userName"];
$userEmail=$_POST["userEmail"];
$userComments=$_POST["userComments"];
$userAddress=$_POST["userAddress"];
$userPhone=$_POST["userPhone"];
$itemList=$_POST["itemList"];
$totalItems=$_POST["totalItems"];
$totalPrice=$_POST["totalPrice"];
ovo obradjuje:
$Body = "<font size=5><font color=#0066FF><b><u>neki text</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>";
ovaj deo (bez $body) ubacim u gornju skriptu umesto ovog reda:
This is something with <b>HTML</b> formatting.
i stigne mi attachemnt i taj red kako je formatiran ali ne i ono sto treba da procita iz swf
Stigne mi ovako:
Od: $userName
Address: $userAddress
Telefon: $userPhone
Email: $userEmail
a ovako bi trebalo:
Od: pa necije ime
Address: necija adresa
Telefon: neciji tel
Email: neciji email
[Ovu poruku je menjao crniluk dana 29.06.2011. u 20:46 GMT+1]
[Ovu poruku je menjao crniluk dana 29.06.2011. u 20:50 GMT+1]