I am successfully able to attach inline image for my system email. I am using template which I have created in mailjet Transactional templates. Now if I use attached image in html but I am not able to see image in my email.
I am sending inline image like this which is working perfectly.
$logoFile = 'full path of image';
$inlineImg[] = [
'Content-type' => 'image/png',
'Filename' => 'logo.png',
'content' => base64_encode(file_get_contents($logoFile))
];
'Inline_attachments' = $inlineImg;
Now, I want to see this image in my email. Using image in mailjet template like this:
<p>Test inline image <img src="cid:logo.png" /></p>
Ref: https://dev.mailjet.com/guides/?php#sending-with-attached-files
I sent them a support ticket after I ran into this problem myself. They are aware of it and working on it.
According to them, inline attached images are displayed on all major email clients except Thunderbird and GSuite (the professional version of Gmail, apparently). Their test email (the curl command in the documentation you refer to) does work with Gmail.
In which email clients do you observe issue? There is a known issue with inline attachments not rendered properly in Thunderbird and few other minor mail clients due to the required specific "Content-type" by the mail client. Inline images should be displayed properly in all major email web services - Gmail, Yahoo etc. If one of the latter platforms are affected, please open support ticket for additional investigation.
Related
I need to send a link within HTML email using CodeIgniter.
first trial:-
send an email to using Gmail server, then the link will be sent successfully without any corruption.
Second trial:
I am using Microsoft Exchange Server.
when sending the link within the HTML email, the link will be received corruptly!!
I don't know why? Then the problem occurred when using only Exchange server.
correct link
http://000.00.0.00/s/admin/r?i=7&e=hana#dom.edu.com
corrupted link
http://000.00.0.00/s/admin/r?i=7&e=hana#do=.edu.com
If I put it within a href tag
correct link
http://000.00.0.00/s/admin/r?i=7&e=2
corrected link
http://000.00.0.00/s/admin/r=i=7&e=2
My IP= 000.00.0.00, it is not the actual but it is just an example
You have to change the crlf setting to use Exchange as an SMTP server.
Add $this->email->set_crlf( "\r\n" );to your controller or add $config['crlf'] = "\r\n"; to your email config file!
The equal signs getting substituted into your email message are a dead giveaway that the end of line character is the issue.
I'm looking for a way to capture and manage email data using PHP. Basically, what I want to do is capture all the data in an email and then manipulate this data to my specification.
For example, say, I send an email containing a .zip file attachment to myemail#myproject.com, I want to be able to:
Get the attachment and place it in a specific folder on my site
Get the text content of the email
Get the subject of the email
Get the sender's info i.e. email address
Anyone know how I can get this done efficiently with PHP. I'm using LAMP by the way.
Thanks.
Start with PEAR Mail_mimeDecode. What you are looking to do is ambitious but can be done.
Basically what you will be doing is:
Instructing your MTA to deliver mail from an address to a pipe into your PHP script. Postfix and Sendmail can handle this with an alias like:
myemail: "|/path/to/your/parsingscript.php"
Parsing out the parts of the MIME email message
Locating and storing attachments after decoding them from base64 (or other encoding)
Parsing the headers.
Your PHP script will likely read the email message from STDIN and then pass the string to mimeDecode, which creates an object containing all the MIME parts.
Assuming your message was received into $str from STDIN, something like this gets you started:
$mime = Mail_mimeDecode::decode(array('include_bodies'=>TRUE, 'decode_headers'=>TRUE, 'decode_bodies'=>TRUE, 'input'=>$str));
// get the recipient To address:
$to = $mime->headers['to'];
I am sending emails with phpmailer package and using the package with codeigniter framework. I have made a helper function out of the phpmailer package which takes arguments as sender's address, recipient's address, subject and message body. Everything goes fine and the message is delivered to the inbox.
My problem is I have a large body which can be a seperate html file. For this I have created a view and I am trying to send the argument $this->load->view('viewname'); through the helper function in my controller. But instead of displaying the body in mail I get the file displayed on my final view page and the mail body goes blank. Any idea how I can achieve
Using $this->load->view('viewname'); without any additional parameters will output the view. What you need is to set the third parameter to TRUE as suggested in the Returning views as data of the CodeIgniter User Guide's View documentation.
Example:
$string = $this->load->view('viewname', '', true);
I am using Zend Framework to send mail.
It's doing something very odd, the content type, content dispostion, MIME version and content type encoding are all showing up in the header section (under the subject) of the email in GMail and in Outlook.
The content of the email was also being included twice in the email, once as plain text and once as HTML. I stopped this by just using setBodyText() instead of using setBodyHtml() too. I had seen somewhere that you can use both. Now I just use setBodyText() like this
$mail = new Zend_Mail('utf-8');
$mail->addTo("mail#mail.com");
$mail->setSubject("Registration info");
$mail->setFrom('do-not-reply#mail.com', "A Name");
$mail->setBodyText($this->view->render('emails/register.phtml'));
$mail->send();
This has been solved. It was an error with the host receiving the email. The fact it was in Outlook or GMail made no difference as the error was with the host.
Is there a way to attach an image to an html formatted email message created in PHP?
We need to ensure that a corporate logo is on emails sent to clients who may not have access to the internet whilst reading their email (They will obviously have it to download the files).
Try the PEAR Mail_Mime package, which can embed images for you.
You need to use the addHTMLImage() method and pass a content id (cid), which is a unique string of text you will also use in your img's src attribute as a cid: URL. For example:
include('Mail.php');
include "Mail/mime.php";
$crlf = "\r\n";
$hdrs = array(
'From' => 'foo#bar.org',
'Subject' => 'Mail_mime test message'
);
$mime = new Mail_mime($crlf);
//attach our image with a unique content id
$cid="mycidstring";
$mime->addHTMLImage("/path/to/myimage.gif", "image/gif", "", true, $cid);
//now we can use the content id in our message
$html = '<html><body><img src="cid:'.$cid.'"></body></html>';
$text = 'Plain text version of email';
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('mail');
$mail->send('person#somewhere.org', $hdrs, $body);
It's probably easiest to use some library that can deal with email attachments. For example, PEAR's Mail_Mime.
PEAR's Mail_Mime package is what you're after here.
Once you've set your message up, adding an attachment is as simple as:
$mime = new Mail_mime("\n");
$mime->setTXTBody($msg_text);
$mime->setHTMLbody($msg_html);
// Add gif as attachment to mail
$mime->addAttachment("/path/to/image/smile.gif", "image/gif");
$body = $mime->get();
$headers = $mime->headers($headers);
$mail->send("joe#bloggs.com", $headers, $body);
If you're looking for your logo to display in a particular place in the email - rather than solely as an attachment - you can do the following:
// In your message html:
<img src='logo.gif' alt='Our logo' />
// PHP:
$mime->addHTMLImage('/path/to/image/logo.gif');
This approach can have mixed results depending on your user's mail client, so before sending it out try testing your format on dummy gmail, yahoo and hotmail accounts.
Are you rolling your own, or using a
prefab class? I recommend PHP
Mailer[0] myself, and there's also
PEAR::Mail_Mime[1] among others that
Google would be happy to help you
find. I've been using PHP Mailer to
send messages with embedded images[2]
for years without a hitch, though bear
in mind that each image increases the
email's bandwidth weight hugely, so
generally it should not be used for
anything in bulk. And to echo Bill,
do make use of the text-only alternative too.
[0] http://phpmailer.sourceforge.net/
[1] http://pear.php.net/manual/en/package.mail.mail-mime.php
[2] http://phpmailer.sourceforge.net/docs/PHPMailer/PHPMailer.html#AddEmbeddedImage
taken from http://lists.evolt.org/archive/Week-of-Mon-20060612/183029.html
There are more than enough answers here that should help fix your specific problem, but I just thought it might be worth pointing out that you may well have a larger problem that you hadn't considered.
Specifically - writing emailers to be sent via PHP is filled with potential gotchas and should only be done if you have a really good idea of what can go wrong.
If you're planning on sending emails fairly intensively I would strongly suggest doing it through either a dedicated email marketing client or implementing one of the many email marketing API's out there that will send it for you. (mailchimp is apparently a decent one).
Try out swiftmailer here is a good example how to use embedded image http://swiftmailer.org/wikidocs/v3/embedding_images?s[]=embed