How to specify an email drop location - php

I'm using Drupal CMS on top of PHP and IIS. When I send emails containing embed images, the images are not displayed in Outlook.
I'm trying to isolate the problem.
There is nothing in Drupal or Outlook which will allow me to view the complete message body with headers.
Is there a way to configure PHP to write the email to a folder on disk instead of sending the email?

you can write it to a text file instead of sending, just need to find the place where it happens:
$folder=dirname(__FILE__)."/emaildir";
$txtfilename=time().'.txt';
$emailstr=$header . "/n" . $message . "/n";
instead of mailto() or whatever function just write to file
$fh=fopen($txtfilename,"w");
$fwrite($fh,$emailstr);
fclose($fh);
This is written from my head, you might want to check for mistakes but you get the picture

Related

How to prevent phpmailer sending embedded image as an attachment on Gmail?

I am sending an email with the logo of a company in it. However, I find it annoying when it shows the .png file on the list of emails on Gmail. Upon clicking the email, the logo is there and there's no attachment (which is good). But I really need to remove the file when viewing on the email list. See the image below.
is there a way where I can remove this "email-logo.png"?
.
.
$mail->AddEmbeddedImage('img/email-logo.png','logo');
.
.
$mail->Body = "<img src='cid:logo'>";
.
.
You can try using
$mail->clearAttachments();
I resolved to putting the src attribute of the image to a remote link e.g src="http://somesite.com/image.png". I resolved to this since I always saw embedded images always coming as attachments as you have mentioned. But some clients block remote content as I have seen with this.

mailto: unable to add attachments

I have an HTML link. I'm using mailto to open up the mail when a user clicks on the link.
I'm able to set the to email id and subject but I'm not able to add an attachment.
This particular form is now in localhost but it will be moved to live server later. These attachment files are stored in a folder and I get the path to these files from a PHP variable.
I tried passing the path to it but it didn't add the attachment.
How can I make this happen?
Here's the sample code.
$filePath = 'C:\xampp\htdocs\sampleProject\attachments\pdfs\samplepdf-03.pdf'
<a href="mailto:?subject=Pictures from PhotoAlbum
&body=This is the body text
&attachment='<?php echo $filePath; ?>'">
Email This
</a>
You can't. The mailto: URI scheme doesn't support attachments (and the client wouldn't usually have access to the web server's hard disk anyway).
Consider sending the email from your PHP instead of from your visitor's email client.

png attachment generated by an API in phpmailer

I'm trying to send a .png image to my user via phpmailer. The image is shown when I use <img> tags, but I want it to display as a real attachment that the user can open/save/print (like in this screenshot). I read that I can use $mail->addStringAttachment for this. So I tried this, and it does send an attachment with the email, but when I try to open it, it says that Windows Picture Viewer can't open the file. Also saving to my computer and then opening with Paint doesn't work, it tells me thats not a valid file or something. I think this is because it's no static image, but an image generated by an API, namely:
$qr = 'http://api.qrserver.com/v1/create-qr-code/?data=' . $guid . '&size=250x250';
So this image should be sent as an attachment. Does anyone know how I can make this work?
I got it to work fine as an attachment by doing the following:
$qr = file_get_contents("https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example");
$mail->addStringAttachment($qr, "qr.png");
The reason it's failing is that you're trying to attach the URL as image data. You need to fetch the data from the URL first, then attach it to something.
Go one step at a time - make sure that you're getting back valid image before trying to email it - e.g.
file_put_contents('qr.png', file_get_contents($qr));
and make sure you get a valid image saved in there. When you know that's working, then try and email it with
$mail->addStringAttachment(file_get_contents($qr) 'qr.png');
Though perhaps with a bit more error checking!

disable opening pdf in browser php

I am using FPDF plugin. I want to send email with pdf file. Everything is working fine. But, the problem is, after sending email my browser still shows the pdf file because of the content type header. Is there any way to disable that thing in certain condition?
Thanks.
If you use $pdfContent = $pdf->Output('', 'S'); there shouldn't be any content send. See here for more details.

PHP Swift Mailer attach FPDF Problems

I am having some issues with trying to get SwiftMailer to attach a file I have created with FPDF. Basically I have a page called createPDF.php that is dynamically generated based on the ID number in the URL. This page is set to output the PDF inline using $pdf->Output("filename.pdf",I);. What I want to do is to be able to attach this file to an email using SwiftMailer from another page simply by calling my createPDF.php?id=xxx link.
From the PHP page where I want to send the email from, everything works, except the attachment. It attaches something, but not what I want and it is not viewable in a PDF viewer on my local machine. The line specific to the attaching the file is:
->attach(Swift_Attachment::fromPath('createPDF.php?id=xxxx'))
This does not work, but surely, it must be possible without saving the file on my web server by FPDF.
Is this possible? If so, how?
Thanks!
The problem here is Swiftmailer gets the file contents, it does not execute your php file. So the contents of your PDF will the code that is in createPDF.php.
why cant you safe the file first? You should be able to safe it and delete it when your email is sent.
<?php
$id = "xxx";
$fileName = "tmp/".sha1(time()+mt_rand(0,99999999));
include "createPDF.php"; //saves it to $fileName
->attach(Swift_Attachment::fromFile( $fileName )->setFilename('blaha.pdf'));
unlink($fileName);
Ok, so I just figured this out.
Basically I made a new PHP file with the bulk of my createPDF.php file as a function and simply passed in two variables into the function as my $id and an $output variable. $output is simply the way that FPDF outputs the file — inline, etc... I then set the function to return the output of the FPDF. In my createPDF.php file I simply call my function passing in $id and 'I' as the variables so it displays the correct PDF inline in the browser.
In my sendEmail function I simply pass in $id and 'S' and set it to a variable $content, which I pass into SwiftMailer as an attachment.
Works great.
Thanks for your help!

Categories