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));
Related
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
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 --;
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
PHP imap problems
I need to be able to use my mail (gmail) from a php script. But wherever I try, the email body comes out all rubbbish with characters like =3D and random equals signs. Sometimes it comes in as base64 or nothing at all. How can I get an email and display it in HTML Purifier clean html or plain text in a pre tag if no html is available.?
$overview = imap_fetch_overview($inbox,$email_number,0);
$body_pre = imap_fetchbody($inbox, $email_number, 2.1);
$message = imap_fetchbody($inbox, $email_number, 2.2);
$message = base64_decode($message);
if (empty($message)){
$message = $body_pre;
$message = preg_replace('#(https?://([-\w\.]+)+(:\d+)?((/[\w/_\.%\-+~]*)?(\?\S+)?)?)#', '$1',$message);
$message = '<pre>'.htmlentities($message).'</pre>';
}else{
$cleanconfig = HTMLPurifier_Config::createDefault();
$cleanconfig->set('Core.Encoding', 'UTF-8');
$cleanconfig->set('HTML.Doctype', 'HTML 4.01 Transitional');
$purifier = new HTMLPurifier($cleanconfig);
$message = $purifier->purify($message);
}
this code, $message just comes blank.
The message with "characters like =3D and random equals signs" is quoted-printable encoded. You can decode using php with quoted_printable_decode.
There are different ways how mail messages can be encoded, like quited-printable or base64. The sender decides on the used encoding.
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
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");