Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Slanje attacha preko php koda

[es] :: PHP :: Slanje attacha preko php koda

[ Pregleda: 1276 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

gagacar
Dragan Markovic
Student, TFZR
Beograd

Član broj: 209656
Poruke: 68
*.ADSL.neobee.net.



+1 Profil

icon Slanje attacha preko php koda23.01.2009. u 21:12 - pre 185 meseci
Potrebna mi je pomoc oko php koda za slanje fajla mailom. Gledao sam na nekim forumima i najbojle resenje sto sam nasao je prikazano dole. Glavni problem je to sto on salje fajl koji se zove slika.jpg i on mora da bude u direktorijumu gde je i fajl sa formularom. Pokusao sam da umesto slika.jpg ubacim <?php echo $slika; ?> gde je $slika fajl koji se uploaduje i nista

pomozite mi gde gresim.

OVO JE KOD KOJI SAM NASAO NA NETU

Citat:


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



A OVO JE STRANA (FORMA I KOD) KOJA NE RADI

Citat:



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$submit = @$_POST['submit'];
$upload = @$_POST['upload'];
$slika = @$_POST['slika'];

if (!empty($submit))
{
?>
<?php


//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Saljem ti file';
//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("$slika"));
//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



--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Pozdrav!!!</h2>
<p>Salje <b>FILE</b> STVARNO.</p>

--PHP-alt-<?php echo $random_hash; ?>--

--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/jpg; name="<?php echo $slika; ?>" // cini mi se da ovo ne cita kako treba
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 ? "poslato" : "greska";

?>
<?php
}
?>

<form name="form1" method="post" action="">
<p>
<input type="file" name="file" value="<?php echo $slika; ?>" size="35" maxlength="255" />
</p>
<p>
<input type="submit" name="upload" value="Upload" />
</p>
<p>
<input name="submit" type="submit" id="submit" value="posalji">
</p>
</form>
</body>
</html>


 
Odgovor na temu

Nikola Poša
Backend (PHP) developer
Beograd

Član broj: 173839
Poruke: 1616
*.adsl-1.sezampro.yu.



+33 Profil

icon Re: Slanje attacha preko php koda23.01.2009. u 21:35 - pre 185 meseci
Moj predlog ti je da za tu svrhu koristish Swift Mailer. Ovde imash primer kako se uz pomoc te aplikacije shalju attachment-i.

Swift se inache ne oslanja na PHP-ovu ugradjenu f-ju mail() (koja inache crpi mnogo resursa pri slanju mejlova), vec ima neki svoj algoritam koji komunicira direktno sa SMTP serverom.

Predlazhem ti da Swift koristish po default-u za slanje email-ova u PHP-u.
 
Odgovor na temu

Jbyn4e

Član broj: 422
Poruke: 6049
*.ptt.rs.



+257 Profil

icon Re: Slanje attacha preko php koda23.01.2009. u 22:36 - pre 185 meseci
Citat:
Pokusao sam da umesto slika.jpg ubacim <?php echo $slika; ?> gde je $slika fajl koji se uploaduje i nista

pomozite mi gde gresim.

Gresis sto nisi procitao o file upload-u:
http://www.php.net/manual/en/features.file-upload.post-method.php

inace bi znao da se upload-ovani fajl NE prebacuje automatski u direktorijum u kojem je formular/php skript.
Kad sve ostalo zakaže, pročitaj uputstvo...
 
Odgovor na temu

[es] :: PHP :: Slanje attacha preko php koda

[ Pregleda: 1276 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.