I have a gmail account; Three other emails are related to this one.
When I receive an email at xxx#mydomain.com it will be transferred to xxx#gmail.com.
Also when I send a message I can use an alias which mean that using gmail I send a mail with my xxx#mydomain.com.
When I use imap_search, From xxx#mydomain.com or To xxx#mydomain.com the result is blank but messages exist in my Inbox. Is this a problem of imap_search?
The solution is:
The default folder when we make imap_connection is INBOX. When we try to make imap_sort or iamp_search. We don't get anyresult. We have to switch to the folder which contain all messages for example [GMAIl]/All.
Related
When I send an email using phpmailer to gmail, and I look the email source, I see the following next to the "from" field:
"Using PHPMailer 6.1.7 (https://github.com/PHPMailer/PHPMailer)"
For security reasons I'd prefer to remove that if it's possible, but I don't know if this is Gmail being smart or phpmailer appending it to every email message I send.
How can I remove it?
Thanks
This appears in the X-Mailer header. As per the docs, you can remove this header altogether by setting it to a space, like this:
$mail->XMailer = ' ';
If it's appearing somewhere else, I'll need to see the rest of your code and the headers of a message you've received in gmail.
I was trying to read the gmail mail box using imap_headers and imap_header() function available in php, it was working fine without any problems. Here in gmail imap_header() function gives the count of only un-read mails and imap_headers($message_number) function would take the message number as input and would return the header information of the mail. Executing imap_fetchstructure() and imap_fetchbody() the message would be marked as read and that message would not come in the next run, since it was marked as read.
Now when I am using office365 account the function imap_header() is returning the count of all mails in the inbox and not the unread mails count, also as contrary in previous case imap_fetchstructure() and imap_fetchbody() are not marking the mail as read and hence the read mails also get tracked in the next job cycles.
Any inputs on this is really helpfull.....Thanks:)
The imap_header() will give you all the mail as its definition.
You should use imap_search() to filter out the unread mail.
You can use the below code:
$imapobj = imap_open(SERVER,USERNAME,PASSWORD);
$result = imap_search($imapobj, 'UNSEEN');
foreach($result as $res=>$value){
$maildetails = imap_headerinfo($value);
$status = imap_setflag_full($imapobj, $value, "\\Seen");
}
I'm trying to get mails using imap_sort.
My email adresse contain a lot of related email box.
Example: xxxx#gmail.com i'm applying imap_sort on is related to xxx#hotmail.com and is related to xxx#mydomain.com.
The result i get is only for those related to xxx#gmail.com and not related to other accounts even the mail exist in my gmail acoount.
The code i'm using actually:
$result = imap_sort($mail,SORTSIZE ,0,SE_UID,$search_criteria);
foreach ($result as $key => $value) {
extract_mail($mail,$value);
}
$search_criteria contain is FROM an email and is TO an email.
What i need actually is to extract all mail FROM and TO this mail even if the communication is between other accounts but exist in gmail with different alias.
The answer is: We have to use the All Folder and not the default folder whish is Inbox when connecting using imap_connect.
After calling the mail function I would like to get the complete mail message that I just sent. Not just the subject and content field but also auto generated information such as Date and Content-Transfer-Encoding. That is the entire message. How do I do that?
PHP doesn't actually send the mail, so it won't know about any of that. All the mail() function does is pass your stuff on to the sendmail binary (or whatever SMTP server you use instead) and return whether or not that was successful. The rest is up to the SMTP server.
Best suggestion I can offer is to have the mail BCCd to an account you control and parse the desired info from there.
I'm trying to handle bounced message and send to a responsible System Administrator.
I use CakePHP Email Component to send the message. On server side, I use postfix to transport the message.
function sendAsEmail($data) {
$Email->sendAs = 'html';
$Email->from = $user['Sender']['username'] . '#example.com';
$Email->return = Configure::read('App.systemAdminEmail');
$Email->bcc = array($data['Message']['recipient_text']);
$content = 'Some content';
$Email->send($content);
}
As you can see above, I set the $Email->return to sysadmin's email which it will send all the bounced message.
On postfix configuration, I tried creating a bounce.cf template and set bounce_template_file. http://www.howtoforge.com/configure-custom-postfix-bounce-messages
How do I get the bounced message and send it to System Administrator?
I think what you'll need to do is to use an SMTP (or I suppose POP3) connector for PHP. Then you'll basically have to create your own PHP email client that will login to the server, ask for the messages that have been bounced, and parse them appropriately.
I would think there would be a CakePHP component for this, but I can't find one.
I would recommend that you use an Envelope Header in your email. Otherwise you'll be stuck trying to parse the recipient server bounce, and those are very very inconsistent. If you use the VERP (variable envelope return protocol?) header, you can encode a unique hash into the email address which should be really easy to parse out in your PHPEmailClient.
More info on VERP: http://en.wikipedia.org/wiki/Variable_envelope_return_path
Cake-specific VERP stuff: http://www.mainelydesign.com/blog/view/setting-envelope-from-header-cakephp-email-component
I also highly recommend that you look into using SwiftMailer. It has a lot of plugins; you might find a base PHP SMTP client that you can easily modify to do what you need. http://swiftmailer.org/