Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mail awkward change to sent content

Tags:

json

php

email

i'm sending a list of url's with php mail. The problem is that exactly one link gets transformed. However, when i try to send only this one link - it works.

Result at the moment:

....
https://scontent! .cdninst agram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11049164_453900378092870_2016147159_n.jpg
....

Wanted Result

...
https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11049164_453900378092870_2016147159_n.jpg
....

As you can see the ! and some spaces appear

This is my code:

$to      = '[email protected]';
$subject = 'mySubject';

$arr = json_decode($string, true);
$message = '';

$arr = $arr['data'];
foreach ($arr as &$value) {
    $message .= $value.'<br />';
}

$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion()  . "\r\n";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers);

The string looks like this:

$string = '{"data": ["https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11049164_453900378092870_2016147159_n.jpg"]}';

i'm decoding the url's from a json string. This works fine when using a single one. I'm currrently testing with around 30 links and only this one link gets broken.

Ideas?

UPDATE:

when using:

echo $message;

the string looks fine. The problem only appears after sending the mail.

UPDATE 2: Complete $string:

$string = '{"data":[
"https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11022962_1622439674642143_1096883351_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11022968_805054996198636_1309286009_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11022880_1423922187907036_917404870_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/10986377_1627498740796578_1852142680_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/s150x150/e15/928667_892060397523291_369749441_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xtf1/t51.2885-15/s150x150/e15/11024100_808085365911650_996017863_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e15/11055960_1404015356578720_1277867740_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e15/11055777_816808825080092_1542857273_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e15/11055471_841674382559292_1230638428_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11015498_361414020713408_1088438153_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e15/11008375_798420746919485_1231742350_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/10787706_1073162062697744_958846105_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/s150x150/e15/11055503_1563023603973925_1133173525_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/10413863_1600753446833891_1231697708_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11055726_1574126762827213_1177337723_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xtp1/t51.2885-15/s150x150/e15/11004987_1642603925967855_119269404_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11055693_902276879824326_64336413_n.jpg",
 "https://scontent.cdninstagram.com/hphotos-xpf1/t51.2885-15/s150x150/e15/11049164_453900378092870_2016147159_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/10946319_803454546417844_1425116400_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/s150x150/e15/11008004_1544347675828229_1335095984_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e15/11008078_330573980474432_104629134_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11189632_1438250796488739_1920042106_n.jpg",
 "https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e15/11373935_828515147227862_998871606_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e15/11272073_1601246710147452_2026113921_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11191056_1566823826912605_513606088_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xat1/t51.2885-15/s150x150/e15/11176380_875274085879731_345551882_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpa1/t51.2885-15/s150x150/e15/11199535_1422045371437335_873505586_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11189551_1581295318796082_2009128397_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11208345_767477406707058_569575819_n.jpg",
"https://2kguzbby0.igsonar.com/hphotos-ak-xfp1/t51.2885-15/s150x150/e15/11193001_381540205362927_573897005_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpa1/t51.2885-15/s150x150/e15/11208605_1607125916200571_200672539_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11203404_1441230966188039_1468562464_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/s150x150/e15/11208226_1607707389487979_2115490962_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11189286_415149128646596_1948742113_n.jpg",
"https://scontent.cdninstagram.com/hphotos-xpa1/t51.2885-15/s150x150/e15/11190217_352891078253491_608612571_n.jpg"]}';
like image 480
Frnak Avatar asked Jun 08 '15 11:06

Frnak


2 Answers

Try to add newlines in your mail ("\n") between your urls, in order to limit the length of your text.

$message .= $value . "<br />\n";
like image 152
jpclair Avatar answered Nov 02 '22 01:11

jpclair


I would highly suggest using a library like swift mailer. However, your problem may be that a character in the link is escaped. The link may also contain hidden encodings in utf-8, strip it to ascii and paste it in whatever text editor you are using and try again.

like image 39
Satbir Kira Avatar answered Nov 02 '22 00:11

Satbir Kira