PHP How to set a bitmask parameter. imap_fetchbody adds '=' to string - php

I'm using some PHP imap_functions to automatically process emails.
However the emails have to stay in HTML format and the function imap_fetchbody seems to add '=' as the end of some lines meaning my html parser cannot parse it correctly.
I think it is because FT_INTERNAL needs setting but whatever I try it still does the same.
How do I add a bitmask set of parameters or stop the function from doing this.
$content .= imap_fetchbody($inbox, $email_number, "1", FT_UID & FT_PEEK & FT_INTERNAL);
$content .= imap_fetchbody($inbox, $email_number, "1", 124);

Not a great solution, but it works fine for me:
$body = preg_replace("/=(\r?)\n/", '', imap_fetchbody($mailbox, $message, $part));
Hope it helps in some way

Related

php imap_fetchbody returns strange characters

Im trying to get the actual text message part of the email with:
$body = imap_fetchbody($inbox, $email_number, 1.2);
Problem is I get this:
WXuQFOW1/53v6+6Z2Zmdnd1Z9gW7vHYREHZZtzaA4IOAMQKJmBARKfNWkwjRingtklgatEwuPlG4
RI2liSZKAAvwFRKuIlwVUYw8RJ4iKwu7yz7nuTPd/Z37R8/Mzq6zat2qm1RtV1dRS3d/33d+53fO
+Z0zxMxIXwwGExEYzKwIUEAoEv3w+Nljp86FIjFDlyXBgknVw0dXBKWuESCIAHIWISIM6Uvr9xc7
9jIY4Wji9Xc+
Do I need to do any kind of encoding here?
I had the same problem and I solved by placing this code:
$message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,2));

How to get imap body text with german locale in php?

Facing the issue that when I try to get the body of an email through imap in php, the content of the variable $body is
Jääätzt Kööönmän umläute mit ÄnhÄÄÄng
instead of
Jääätzt Kööönmän umläute mit ÄnhÄÄÄng.
I do not understand where the problem is, all other characters like ?,!,$ are working fine, just german characters like ä,ö are making those problems.
The code-block in php I am using is
$body = imap_fetchbody($mbox, $overview->msgno, 1.2);
if (!strlen($body) > 0) {
$body = imap_fetchbody($mbox, $overview->msgno, 1);
}
Do you have any ideas? I am really desperate.
The Mail you try to show is not in the same encoding as the headers of your website. That's why your browser can't show the special chars properly, like the Umlaut in this case.
You can for example convert them to utf-8 with imap_utf8
$body = imap_fetchbody($mbox, $overview->msgno, 1.2);
if (!strlen($body) > 0) {
$body = imap_fetchbody($mbox, $overview->msgno, 1);
}
$body = imap_utf8($body);
http://php.net/manual/de/function.imap-utf8.php

PHP change string parsed from email

Using a PHP script file to filter emails. Everything is working properly, but it seems that if I were to initiate a conversation between a cell phone (Verizon Wireless) and the SMTP server, Verizon changes the format of outgoing messages.
For example, I need to respond to an email using XXX#vtext.com but Verizon will respond with XXX#vzwpix.com which cannot be responded to. So I created the following code to try and remove and replace the #vzwpix.com but it still isn't sending the mail. I know the code is working however because if I change the $from in the mail function to XXX#vtext.com the code works and sends the message.
//Parse "from"
$from1 = explode ("\nFrom: ", $email);
$from2 = explode ("\n", $from1[1]);
if(strpos ($from2[0], '<') !== false)
{
$from3 = explode ('<', $from2[0]);
$from4 = explode ('>', $from3[1]);
$from = $from4[0];
}
else
{
$from = $from2[0];
}
if(strpos ($from[1], '#vzwpix.com') !== false) {
str_replace('#vzwpix.com', '#vtext.com', $from);
}
var_dump( mail( $from, "Hi", "What is the email:"));
I am using var_dump just for developmental purposes by the way.
I did some research and I think the best way to do this maybe is to explode the XXX#vzwpix.com at the # symbol, then run a str_replace('vzwpix.com','vtext.com', $from5); However, that didn't work and then I thought maybe implode it after running a str_replace?
If the bad domains are static, why don't you explode on 'vzwpix' and then implode on 'vtext'? This should replace each of the bad instances in you address string.
You forgot to get the result of your str_replace
$from_with_vtext=str_replace('#vzwpix.com', '#vtext.com', $from[1]);

How to get special characters of the body of an email using imap with PhP?

I'm using imap with php to get the body of my emails.
With what've coded so far, I am not getting the special characters and weird formatting at the end. For instance, if I send myself an email (with a regular email client such as Apple Mail) that says:
Test with characters é à and some ! that rock.
What I get with php is:
Test with characters =C3=A9 =C3=A0 and some ! that rock.=
I've tried re-sending the body through the mail function of php with those headers, but I'm still getting the same problem.
$headers="From: address#email.com" . "\r\n" . "MIME-Version: 1.0" . "\r\n" . "Content-type:text/html;charset=UTF-8";
mail($sendTo, $message, $noBody, $headers);
I've tried addslashes(), which didn't help either.
Sample of my code here:
$imapLink=imap_open("{".$mailbox."}INBOX",$username,$password);
$mailBoxInfos = imap_check($imapLink);
$mailList = imap_fetch_overview($imapLink,"1:".$mailBoxInfos->Nmsgs);
if(isset($mailList))
{
$numMess = imap_num_msg($imapLink);
while($numMess>0) {
$message = imap_body($imapLink, $numMess);
$numMess --;
}
}
$imapClose = imap_close($imapLink);
Hope you can help me with that!
Thanks in advance!
Arthur
The =XX you see in your text is called "Quoted-Printable Content". It's used to display character which can't be displayed in 7-bits.
You can use quoted_printable_decode() to convert it back to a readable string.
So this should work:
$message = imap_body($imapLink, $numMess);
$message = quoted_printable_decode($message); // <-- add this line
$numMess --;

How to have a variable in a mail line

okay, here is the code
while (!feof($text)) {
$name = fgets($text);
$number = fgets($text);
$carrier = fgets($text);
$date = fgets($text);
$line = fgets($text);
$content = $_POST['message'];
$message .= $content;
$message .= "\n";
$number = $number;
mail("$number#vtext.com", "Event Alert", $message, "SGA");
Header("Location: mailconf.php");
}
I am trying to get a message sent to a phone, I have 'message' coming in from a text area, and then I assign it to "$content" then I put "$content" into "$message" and then as you can see, in my mail line, I want the address to be the variable "number"#vtext.com I have the while loop because there are many people in these files I wish to send a message to...
When I change the "$number#vtext.com" to my email address, it sends everything fine, I just cannot seem to get it to send to a phone number, please help!
thanks!
The problem is that fgets includes the newline character as part of the return. So you are effectively sending an email to:
1234567890
#vtext.com
Which of course is invalid. Change your line that reads $number = $number to:
$number = trim($number);
And the rest of your code should function as expected, with the email being received on your phone.
Part of my original answer
I would highly recommend using a (probably paid) service to send SMS messages to phones if you need anything remotely reliable. A quick search yielded a few results:
PHP/SMS Tutorial
A list of 5 ways to Text for free <-- This link is dated, but might still be helpful
You need to append the number variable and the "#vtext.com" literal string together:
mail($number . "#vtext.com", "Event Alert", $message, "SGA");

Categories