E-mail met bijlagen

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Adriaan Biesheuvel

Adriaan Biesheuvel

13/10/2010 14:48:34
Quote Anchor link
Ik probeer al een tijd om een E-mail met bijlagen te maken.
Ik krijg wel een bijlage maar geen inhoud.
Als ik dan de inhoud heb dan krijg ik geen goede naam van de bijlagen.
De bedoeling is dat ik een script heb die een E-mail verstuurd zonder invoegen.
Die wordt gebruikt voor Cron jobs zodat de klant een mail krijgen als er weer een factuur verzonden wordt.
Dit is het script het verzenden met bijlage gaat goed maar zonder data.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
$naam
= 'Mijn zelfs';
$email ='[email protected];
$file = '
2010-20-06.pdf';
$onderwerp = '
Factuur';
//geneer boundary
DEFINE('
bound',md5(uniqid(time())));
//check request method


$headers = "From: ".$naam." \r\n";
$headers .= "Reply-To: ".$naam." \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".bound."\"\r\n";
$headers .= "Content-Disposition:  attachment\r\n";
       $fp = fopen($file,'
r');
       $bestand = fread($fp,$file);
       fclose($fp);
$body.= "This is a multi-part message in MIME format.\r\n";
$body.= "\r\n";
$body.= "--".bound."\r\n";
$body.= "Content-Type: text/plain; charset=iso-8859-1\r\n";
$body.= "Content-Transfer-Encoding: 7bit\r\n";
$body.= "\r\n";
$body.= $_POST['
bericht'] ."\r\n";
$body.= "--".bound."\r\n";
$body .= "Content-Type: application/pdf; name=".$file."\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body.= "Content-disposition: attachment\r\n";
$body .= "\n";
mail($email,$onderwerp,$body,$headers);
?>


Kan iemand mij daar mee helpen.
Gewijzigd op 13/10/2010 14:55:12 door Adriaan Biesheuvel
 
PHP hulp

PHP hulp

23/04/2024 10:26:03
 
Aad B

Aad B

13/10/2010 14:59:54
Quote Anchor link
je moet nog iets doen als: chunk_split(base64_encode(file_get_contents($file)));
maar het is complexer om zelf een file toe te voegen. Gebruik phpmailer en het is een fluitje van een cent. Ik heb eerder wel onderstaande oplossing gebruikt maar gebruik nu phpmailer.
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$attachment
= chunk_split(base64_encode(file_get_contents($file)));
//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

test

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

<p>test</p>

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

--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name="Factuur.pdf"
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 );
?>
Gewijzigd op 13/10/2010 15:04:22 door Aad B
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.