IMAP in Php: Marking a message unread/unseen - php

I want to create a script in php to read al mail from a mail acount. I connect to the server, I can see the mails but went I want to seet it back to unseen I can't find a function to do this.

If I understand this page correctly:
http://www.php.net/manual/en/function.imap-body.php
You can use the FT_PEEK option to leave the message as 'unread'.
EDIT AFTER YOUR COMMENTS
Have you looked at this method?:
http://www.php.net/manual/en/function.imap-clearflag-full.php
You are able to clear the \\Seen flag.

Related

How to remove X-CMAE-Envelope from php mail

xample#gmail.com
X-CMAE-Envelope: MS4wfP8FXd8/R+a/LSU6TL5fZ2U9j6XNOlqH2ChNeZRC9M65GyLWs79yxh/WSVP1mWgmTrSR1jubA85EorlFhPmvIANJv+g8Dvba+4+i5Epzjt6Q3cuOetV2
yQT63E6PAR3l9SpC0BsxP9MXrvBLXdYDMIrGANJWNZNOR8b5focPdjP4
[Mail Message]
Whenever I send a mail using PHP, X-CMAE-Envelope is automatically adding in mail body. How can I remove it?
It has been a while ago since this was asked, but if someone else gets the same problem:
I noticed that the envelope message disappears when you start the message body with an extra empty line.
\r\n\r\n Marks the end of the headers and start of the message body.
CMAE stands for Cloudmark Authority Engine and is an e-mail security product (anti-spam). This and others headers are added by this software at a server level. You should check it with your sysadmin.
https://www.cloudmark.com/en/knowledgebase/cloudmark-authority-for-spamassassin/Order-of-startup-for--CMAE-spamd-and-the-MTA
This is not a direct answer, but I didn't find much on the web for this.
While using Python sending an email through gmail to a user#vzpix.com email, it appears the message included the X-CMAE-Envelope based on what the message was. If the message was not only text but included a date and time - then it included the X-CMAE-Envelope otherwise it was not included. With that being said, it appears server-based.
I know this was from a while ago but I recently had the same issue, specifically a colon ":" triggers this. But if you just start your message with \n it fixes it

How to self-send an email with XAMPP-Mercury Mail using php

I've been searching a lot, but can't really find what i exactly need.
Im running a shop-online using XAMPP, and what i want is send emails to the customers with their order but using a specific function.
What this fuction does, is to hide some characters (for security purpose) on the email sent to customers. So i've made the function (looking on internet), but i want to test it now.
This is my function (if it's wrong, i'd really appreciate some help):
<?php
function xtc_hide_iban ($iban) {
$length = strlen($iban);
$lchars = substr($iban,0 ,5);
$rchars = substr($iban, -5);
$iban_hidden = $lchars.str_repeat('*',$length-10).$rchars;
return $iban_hidden;
}
?>
I think it's pretty obvious what i try to do, but i will still explain it:
Get the $iban from customers, and show only the first and last 5
characters when the email is sent e.G
Your IBAN is 'DE123************56789'
So, for now i can send emails from Mercury mail server to 'root#localhost',account i made on thunderbird, (it's the only account that worked for me, because any other with the same server, like 'anyname#localhost' didn't work or couldn't be created, and those who were create with imap before couldn't access to the inbox "could not connected to server, connection refuse", anyway this works with POP3)
Following what i looked before, is that somehow and somewhere i can put a *.php on Mercury folder so i will get a template of how to send the mails (headers, subject,body,etc).
My main question is how and where to do that? make a test php file to make sure my code is doing what i want to do
Thanks in advance

Symfony2 delayed flashbag message when sending mail

I've got an odd problem that I can't put my finger on.
In my controller, I'm sending an email using swiftmailer, setting a flash message using the session flashbag, and redirecting to another page.
public function testAction() {
$this->get('session')->getFlashBag()->add('info', 'test flash message');
$message = new \Swift_Message('test', 'test');
$message->setTo('email#example.com');
$message->setFrom('email#example.com');
$this->get('mailer')->send($message);
return $this->redirect($this->generateUrl('home_page'));
}
After the redirect, I expect to see the flash message, but it seems that something happens when the mail is sent that makes the flash message delayed by one request. That is, I don't see the flash message when I get to 'home_page', but I do if I reload the page after the redirect.
If I comment out the send() call or even set disable_delivery: true in the swiftmail configuration, the flash message works as expected.
I thought I might have found a bug, but when I created a new project (symfony/framework-standard-edition 2.4.1) and tried this, it works even when I send mail. I've checked to make sure I'm using the same releases for swiftmailer, symfony, etc. So, I'm sure it's something with my project, but I am out of ideas of where to go from here.
I'm using PHP 5.5.7, Symfony 2.4.1.
Thanks for your time
A quick fix is to disable spooling for SwiftMailer. I am still uncertain whether this is the actual solution, but it seems to work.
By disabling spooling, the mailer will block execution while sending the mail.
I commented out the line that enables spooling:
#spool: { type: memory }
By default, the mailer will not use spooling but send the mail right away: http://symfony.com/doc/master/cookbook/email/spool.html
I believe there's a bug when using PdoSessionHandler for storing sessions - if you use native session storage the problem goes away and the flash message works as expected with SwiftMailer.
The flash messages (app.session.flashbag) rely on sessions to store the data between page loads.

fake sendmail for windows

I am using fake mail for windows, For long time i got a problem with the FIRST mail i am sending, What i mean is that for example i am using php so i will use this line:
mail("example#gmail.com", "hey", "bye");
If i will load the page with this mail function for the first time the mail function will return false, But the second time and third and so on it will work, But, After some time i can not determine how long exactly, I can say the gmail mail server "going to sleep", And again when i am sending a mail for the first time its like, Ohh you need a mail to send give me a second(the first mail return false), After the mail server got the second it wanted it will send the mail(return true), I did follow this tut, The error appear at the error.log is: Connection Closed Gracefully., Now as i see it there is a problem on my gmail account(some setting i should change), Anyway If anyone got any idea i will be very thankful, Thank you all and have a nice day.
After researching this bug, it seems to be a bug of the mail() function. One alternative is to download the phpMailer library, and implement your mail function there. The other alternative, since you say that the second time it always works, is:
if (!mail("example#gmail.com", "hey", "bye"))
mail("example#gmail.com", "hey", "bye");
In other words, if it fails once then you try again. You might insert a 300-milisecond pause there in case Google needs some time to come back from sleep.

Spam check before sending using Zend_Mail

I'm using Zend_Mail and the following code to send my email messages.
$mail = new Zend_Mail('UTF-8');
$mail ->setBodyText($plainBody)
->setBodyHtml($htmlBody)
->setSubject($subject)
->setFrom(FROM_ADDR, FROM_NAME)
->addTo($email, $name )
->addHeader(MY_HEADER, serialize( array( 'foo' => 'bar' ) ) )
;
I need to check the spam rating for the prepared message and I'd like to do it using SpamAssassin.
I thought to create a file with the contents and running something such as exec('spamc $filename'), but how to get the file content with the full MIME body?
I noticed that there's a _buildBody() function in Zend_Mail_Abstract class (library/Zend/Mail/Transport/Abstract.php) that's return that, but that's a protected function.
Thanks
If you want to use SpamAssasin, then run your email message through spamc:
http://spamassassin.apache.org/full/3.1.x/doc/spamc.html
Spamc is the client half of the spamc/spamd pair. It should be used in
place of spamassassin in scripts to process mail. It will read the
mail from STDIN, and spool it to its connection to spamd, then read
the result back and print it to STDOUT. Spamc has extremely low
overhead in loading, so it should be much faster to load than the
whole spamassassin program.
You can do use in PHP by:
Writing the message into a temporary file and running shell_exec('spamc < message.tmp'), or
Running the command with proc_open() then send message via STDIN.
I am assuming you want to simulate a spam check on the recipient's end. That's an interesting idea, but note that the results it will give you will be far from 100% realistic. After all, it's the sending process that adds much of the vital information that helps determine whether an E-Mail is spam (e.g. the sender IP and routes.)
Anyway, to do this, you will probably have to implement a custom Zend_Mail_Transport class, based on the example of Zend_Mail_Transport_Smtp. Any data that transport class sends to the SMTP server, you would have to re-route to a text file. As far as I can see at a cursory glance, it's going to be a bit of work but not impossible.

Categories