Hey i have make some tag on my sender to make it quite optionable $usernameemail = preg_replace('/@.*?$/', '', $email);
and i have been working with some array so its gonna work with ##UNAME## as the $usernameemail
related, i want to make the tag ##UNAME##, but here the problem , when im putting these ##UNAME## on the message body , it turns out normally as (its should turn out from username@email.com to username) it working to put username , but it didnt work when im putting it on the subject, any help would appreciate, hope my project gonna done. Thanks Alot!
Asked
Active
Viewed 35 times
0

mario
- 144,265
- 20
- 237
- 291

Cahya Darma Wijaya
- 43
- 6
-
`str_replace('##UNAME##', $usernameemail, $body)` Or you can do it as an array of tags to search for and an array of values to replace them with. – ArtisticPhoenix Mar 03 '19 at 01:38
-
Hi @ArtisticPhoenix i have make a config to set my subject as in a config file without changing my sender, ` "subject" => "MakassarSender Function", ` i have set the uname , its just gonna work well if im using ##UNAME## as the calling the $usernameemail , but it didnt work if im using as the "subject" => "##UNAME##" , its just gonna send ##UNAME## on the subject – Cahya Darma Wijaya Mar 03 '19 at 01:41
-
2You should learn to abstract your issues, before googling them e.g. This for example has little to do with phpmailer. That's just string processing/substitution of placeholders. – mario Mar 03 '19 at 01:42
-
it really have been frustating me for fixing this , making its as a mail sender with having so many tags , stackoverflow is the only site i can trust to help me i think – Cahya Darma Wijaya Mar 03 '19 at 01:44
-
Sounds like you've been trying to apply those placeholders at various locations. But you've only shown one example of how you use it. – mario Mar 03 '19 at 01:46
-
im trying to explain as my best, but language is my biggest problem. – Cahya Darma Wijaya Mar 03 '19 at 01:50
2 Answers
1
I would do it like this:
$tags = [
'##UNAME##' => $usernameemail,
'##FOO##' => $foo, //for example of multiple
];
//$email is the content of the email (I would change this to $body as $email implies an email address)
$email = str_replace(array_keys($tags), $tags, $email);
What this does is find the keys
like ##UNAME##
in the $email
text, and replaces it with the value for that key from the array. This way it's easy to keep your tags organized etc..

ArtisticPhoenix
- 21,464
- 2
- 24
- 38
-
can u check my answer below? , using it because have to post some of my script – Cahya Darma Wijaya Mar 03 '19 at 01:49
-
You should edit your question and post the code there, doing it as an answer makes it confusing to other users and discourages other answers. – ArtisticPhoenix Mar 03 '19 at 03:09
-
Sorry, first time using stackoverflow, i will try better next time. – Cahya Darma Wijaya Mar 03 '19 at 03:19
-
I will let it go this time, just don't do it again.... Ha ha, just playing. Good luck! – ArtisticPhoenix Mar 03 '19 at 03:21
0
$usernameemail = preg_replace('/@.*?$/', '', $email);
$date = date('G:i, d M Y');
$file = file_get_contents($msgfile);
$arr = array('##EMAIL##', '##SUBJECT##', '##RANDOMIP##', '##FROMMAIL##', '##FROMNAME##', '##LINK##', '##RANDOMCHAR1##', '##RANDOMCHAR2##', '##RANDOMCHAR3##', '##RANDOMCHAR4##', '##RANDOMCHAR5##', '##RANDOMCHAR6##', '##RANDOMCHAR7##', '##RANDOMCHAR8##', '##RANDOMCHAR9##', '##RANDOMCHAR10##', '##COUNTRY##', '##DATE##', '##NUMBER1##', '##NUMBER2##', '##NUMBER3##', '##NUMBER4##', '##NUMBER5##', '##NUMBER6##', '##NUMBER7##', '##NUMBER8##', '##NUMBER9##', '##NUMBER10##', '##OS##', '##BROWSER##', '##CITYAMERIKA##', '##AMPLOP##', '##UNAME##');
$new = array('' . $email . '', '' . $subject . '', '' . $randip . '', '' . $frommail . '', '' . $fromname . '', '' . $randurls . '', '' . $randstr1 . '', '' . $randstr2 . '', '' . $randstr3 . '', '' . $randstr4 . '', '' . $randstr5 . '', '' . $randstr6 . '', '' . $randstr7 . '', '' . $randstr8 . '', '' . $randstr9 . '', '' . $randstr10 . '', '' . $country . '', '' . $date . '', '' . $randnumber1 . '', '' . $randnumber2 . '', '' . $randnumber3 . '', '' . $randnumber4 . '', '' . $randnumber5 . '', '' . $randnumber6 . '', '' . $randnumber7 . '', '' . $randnumber8 . '', '' . $randnumber9 . '', '' . $randnumber10 . '', '' . $OS . '', '' . $browser . '', '' . $cityamrik . '', '' . $amplop . '', '' . $usernameemail . '');
$repl = str_replace($arr, $new, $file);
return $repl;
I have making a file to organize my tags , called mks.function.php , here i put all my tags to make it clean as possible. @ArtisticPhoenix

Cahya Darma Wijaya
- 43
- 6
-
you don't need to use all those *concentration operators* when creating your array, just a coma separated assignment is good enough... $new = array ( $email, $subject, $randip, $frommail, $fromname, $randurls, $randstr1, $randstr2, $randstr3, $randstr4, $randstr5, $randstr6, $randstr7, $randstr8, $randstr9, $randstr10, $country, $date, $randnumber1, $randnumber2, $randnumber3, $randnumber4, $randnumber5, $randnumber6, $randnumber7, $randnumber8, $randnumber9, $randnumber10, $OS, $browser, $cityamrik, $amplop, $usernameemail ); other than that, are you sure $email has a value? – Stephanie Temple Mar 03 '19 at 02:17
-
$ListBrowser = array('Internet Explorer', 'Firefox', 'Safari', 'Chrome', 'Edge', 'Opera', 'Netscape'); shuffle($ListBrowser); $browser = array_shift($ListBrowser); – Cahya Darma Wijaya Mar 03 '19 at 02:25
-
@Stephanie Temple have to use those because im making tags from shuffle the array, so making it is only option i got, and yes the $email has a value – Cahya Darma Wijaya Mar 03 '19 at 02:26