Email Attachments using php mail() function - Working for gmail but attachments are of null size (0 bytes) for other mailing provider -
i sending email attachments using php mail() function.
it working gmail attachments of null size (0 bytes) yahoo.
here attachment code have used :
$attachment = $pdf->output(" ", "s"); $attachment_final = chunk_split(base64_encode($attachment)); $email_to = $_session['flyer_data']['download_email']; $email_from = $_session['flyer_data']['sender_email']; $email_subject = 'subject'; $email_txt = "<p>check attachment flyer.</p>"; $fileatt_name = $output_file_name; $file = fopen($fileatt_name,'rb'); $data = fread($file,filesize($fileatt_name)); fclose($file); $separator = md5(time()); $mime_boundary = "==multipart_boundary_x{$separator}x"; $headers="from: $email_from"; // email (example) $headers .= "\nmime-version: 1.0\n" . "content-type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "this mime encoded message.\n\n" . "--{$mime_boundary}\n" . "content-type:text/html; charset=\"iso-8859-1\"\n" . "content-transfer-encoding: 8bit\n\n" . $email_txt . "\n\n"; $data = $attachment_final; $email_message .= "--{$mime_boundary}\n" . "content-type: application/pdf; name=\"{$fileatt_name}\"\n\n". "content-transfer-encoding: base64\n\n" . "content-disposition: attachment\"{$data}\"\n\n" . "--{$mime_boundary}--\n"; // send message mail($email_to,$email_subject,$email_message,$headers);
i prefer using html such purposes. can give link file on server using anchor tag in email message.
to write html in email message:
<?php $to = "somebody@example.com, somebodyelse@example.com"; $subject = "html email"; $message = " <html> <head> <title>html email</title> </head> <body> <p>this email contains html tags!</p> <a href="./unknown.pdf">download</a> <table> <tr> <th>firstname</th> <th>lastname</th> </tr> <tr> <td>john</td> <td>doe</td> </tr> </table> </body> </html> "; // set content-type when sending html email $headers = "mime-version: 1.0" . "\r\n"; $headers .= "content-type:text/html;charset=utf-8" . "\r\n"; // more headers $headers .= 'from: <webmaster@example.com>' . "\r\n"; $headers .= 'cc: myboss@example.com' . "\r\n"; mail($to,$subject,$message,$headers); ?>
and purpose, bit weak...sorry...
Comments
Post a Comment