ilch Forum » Allgemein » HTML, PHP, SQL,... » PDF automatisch per Mail versenden

Geschlossen
  1. #1
    User Pic
    Ahrtas Moderator
    Registriert seit
    17.12.2007
    Beiträge
    2.368
    Beitragswertungen
    210 Beitragspunkte
    Also ich habe ein Formular wo der Besucher Name und Mail eingibt und dann Infos anfordert. Die Infos sollen in Form einer PDF-Datei automatisch versendet werden.

    Wie muss das Aussehen dass ich einen "Mail-Anhang" mitsenden kann?

    mail (
    $_POST['wer'],
    $_POST['betr'],
    $_POST['txt'],
    'From: '.$_POST['name'].' <'.$_POST['mail'].'>'
    );



    verwendete ilch Version: 1.1 P

    betroffene Homepage: www.cristiang.de
    0 Mitglieder finden den Beitrag gut.
  2. #2
    User Pic
    FeTTsack Hall Of Fame
    Registriert seit
    27.06.2012
    Beiträge
    188
    Beitragswertungen
    26 Beitragspunkte
    versuch es mal so:

    <?php
    $dateiname = $_FILES['attachment']['tmp_name']; // Dateiname
    //$dateiname = "testdatei.pdf";
    $id = md5(uniqid(time()));
    $dateiinhalt = fread(fopen($dateiname, "r"), filesize($dateiname));
     
     // Absender Name und E-Mail Adresse
    $from = "From: ".$_POST['name']." <".$_POST['mail'].">";
    // Content-Type: 
    $from .= "\nContent-Type: application/pdf; name=$dateiname\n";
    $from .= "Content-Transfer-Encoding: base64\n";
    $from .= "Content-Disposition: attachment; filename=$dateiname\n\n";
    $from .= chunk_split(base64_encode($dateiinhalt));
    $from .= "\n--$id--";
    
    // E-Mail versenden
    mail (
    $_POST['wer'],
    $_POST['betr'],
    $_POST['txt'],
    $from
    );
    ?>
    0 Mitglieder finden den Beitrag gut.
  3. #3
    User Pic
    Ahrtas Moderator
    Registriert seit
    17.12.2007
    Beiträge
    2.368
    Beitragswertungen
    210 Beitragspunkte
    Vielen Dank, das funktioniert so. lächeln

    Was muss ich machen damit das auch mit icmail() anstelle von mail() funktioniert?
    0 Mitglieder finden den Beitrag gut.
  4. #4
    User Pic
    Ahrtas Moderator
    Registriert seit
    17.12.2007
    Beiträge
    2.368
    Beitragswertungen
    210 Beitragspunkte
    Hat jemand noch eine Idee wie ich das mit icmail machen kann?
    0 Mitglieder finden den Beitrag gut.
  5. #5
    User Pic
    Rock@wulf Hall Of Fame
    Registriert seit
    03.06.2004
    Beiträge
    3.282
    Beitragswertungen
    239 Beitragspunkte
    Einen neuen Übergabe Parameter schaffen

    function icmail ($mail, $bet, $txt, $from = '', $html = false)


    Den Rest findest du in der Doku von PHPMailer.

    ZitatZitat geschrieben von phpmailer.worxware.com/?pg=tutorial#3
    Using Attachments

    Sending plain text e-mails is often insufficient. Perhaps you need to attach something to your mail, such as an image or an audio file. Or perhaps you need to attach multiple files.

    There are two ways of attaching something to your mail: You can simply attach a file from the filesystem or you can attach (binary) data stored in a variable. The latter is called Stringattachment. This makes it possible put extract data from a database and attach it to an e-mail, without ever having to actually save it as a file.

    File Attachments

    The command to attach a file can be placed anywhere between $mail = new PHPMailer(); and !$mail->Send(); and it's called AddAttachment($path);. This single line will add the attachment to your mail.

    $path is the path of the filename. It can be a relative one (from your script, not the PHPMailer class) or a full path to the file you want to attach.

    If you want more options or you want to specify encoding and the MIME type of the file, then you can use three more parameters, all of which are optional:
    AddAttachment($path,$name,$encoding,$type);

    $name is an optional parameter, used to set the name of the file that will be embedded within the e-mail. The person who will recieve your mail will then only see this name, rather than the original filename.

    $encoding is a little more technical, but with this parameter you can set the type of encoding of the attachment. The default is base64. Other types that are supported include: 7bit, 8bit, binary & quoted-printable. Please refer to your SMTP documentation about encoding and the differences between types. In general, mail servers will convert encodings they don't want to handle into their preferred encoding type.

    $type is the MIME type of the attached file. Content types are defined not necessarily by file suffixes (i.e., .GIF or .MP3), but, rather, a MIME type (MIME = Multipurpose Internet Mail Extensions) is used. This parameter makes it possible change the MIME type of an attachment from the default value of application/octet-stream (which works with every kind of file) to a more specific MIME type, such as image/jpeg for a .JPG photo, for instance.

    String Attachments

    String attachments have been supported since PHPMailer version 1.29. This method works much like AddAttachment(), and is called with AddStringAttachment($string,$filename,$encoding,$type). The string data is passed to the method with the first parameter, $string. Because the string will become a standard file (which is what the attachment will be when received via e-mail), the $filename parameter is required. It's used to provide that filename for the string data.

    The rest is just the same as described in detail above.

    So, why use AddStringAttachment instead of AddAttachment? Is it for text-only files? No, not at all. It's primarily for databases. Data stored in a database is always stored as a string (or perhaps, in the case of binary data, as as a BLOB: Binary Large OBject). You could query your database for an image stored as a BLOG and pass the resulting string to the AddStringAttachment.

    Inline Attachments

    There is an additional way to add an attachment. If you want to make a HTML e-mail with images incorporated into the desk, it's necessary to attach the image and then link the <img src="cid:CID" /> tag to it. For example, if you add an image as inline attachment with the CID my-photo, you would access it within the HTML e-mail with &ltimg src="cid:my-photo" alt="my-photo" />.

    In detail, here is the function to add an inline attachment:

    $mail->AddEmbeddedImage(filename, cid, name);
    By using this function with this example's value above, results in this code:
    $mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg ');
    For more Information about HTML Email, see the section Using HTML E-Mail.

    Handling Attachments

    If you want to attach multiple files (or strings), just call AddAttachment() or AddStringAttachment() multiple times. All attachments (file, string, and inline) may be stripped from an e-mail by invoking ClearAttachments().
    Meine Postings repräsentieren meine Meinung wenn nicht anders gekennzeichnet.
    MFG Rock@wulf
    0 Mitglieder finden den Beitrag gut.
  6. #6
    User Pic
    Ahrtas Moderator
    Registriert seit
    17.12.2007
    Beiträge
    2.368
    Beitragswertungen
    210 Beitragspunkte
    @Fettsack
    Bei deinem Beispiel sendet es den Text nicht mit.

    Entweder nur Text oder nur PDF, beides geht aber nicht.
    	$dateiname = "testdatei.pdf";
    	$id = md5(uniqid(time()));
    	$dateiinhalt = fread(fopen($dateiname, "r"), filesize($dateiname));
    	
    	$message = 'hallo';
    	  
    	// prepare mail-header
    	$from = "From: Cristian Gheorghiu <info@cristiang.de>";					// <- absender
    	$from .= "\nContent-Type: application/pdf; name=$dateiname\n";
    	$from .= "Content-Transfer-Encoding: base64\n";
    	$from .= "Content-Disposition: attachment; filename=$dateiname\n\n";
    	$from .= chunk_split(base64_encode($dateiinhalt));
    	$from .= "\n--$id--";
    	 
    	// send mail
    	mail (
    		$mail,
    		'Test',
    		$message,
    		$from
    	);
    0 Mitglieder finden den Beitrag gut.
  7. #7
    User Pic
    FeTTsack Hall Of Fame
    Registriert seit
    27.06.2012
    Beiträge
    188
    Beitragswertungen
    26 Beitragspunkte
    oh gut zu wissen lächeln
    ist bei mir nur in benutzung um reports als .xls und .csv zu verschicken.

    schau ich mir an ...
    update folgt lächeln

    lg fetti
    0 Mitglieder finden den Beitrag gut.
  8. #8
    User Pic
    Commiseve1 Mitglied
    Registriert seit
    13.07.2015
    Beiträge
    17
    Beitragswertungen
    1 Beitragspunkte
    ich wusste gar nicht, dass so etwas überhaupt geht. bisher hab ich pDFs im Anhang gepackt udn das war es dann auch ^^
    0 Mitglieder finden den Beitrag gut.
Geschlossen

Zurück zu HTML, PHP, SQL,...

Optionen: Bei einer Antwort zu diesem Thema eine eMail erhalten