PHP: Run chinyorwa vachizvitakudza mufananidzo midzi muna e-mail

muromo ichi runobatsira munhu anoda kuziva kana E-mail iwe akatuma raiverengwa. muchiitiko ichi, pinza chifananidzo mumuviri email shoko, kana akasvinudzwa, achaita kuti pave nekukurukurirana manyorero pamusoro kure Server.

mupiro

nzira iyi zvinowanzoshandiswa e-mail Marketing, zvokuti yatumira anotumira mazana kana zviuru na kuti vanowana no yako aiming kusvika akainangisa, uye mushame zvaunofunga (dzokera) kambeyini, mune mamwe mazwi, kana wacho haana kuverenga kana kwete pakuvara tsambambozha kushambadza.

sei akunoita?
The pfungwa iri nyore, iwe nyore nomuviri email (gutsikana) chifananidzo HTML Tag, pamwe src chizenga zvigunwe, kwete zvakananga chifananidzo sezvazvakanyorwa kunowanzoitwa, asi kuti tsika manyorero vaipinda pamusoro kure Server, apo iwe unogona kuita zvimwe purogiramu uye, ipapo ehe, dzinoshandura chifananidzo (kana kwete). kumbooma? hapana, ona muenzaniso:

1
2
3
<?PHP
  <IMG src="http://seuservidor.com/script.php?email=pessoa@gmail.com&destinatario = Taylor + Lopes" />
?>

Chii?
Cherechedza kuti kana inodzidzisa rinovhura e-mail, rwoga hunganzi mufananidzo achapiwa akatakura, riri zvechokwadi manyorero. Izvi zvinobatsira kuti neindaneti nhamba kunge aiona, kusanganisira Pakusarudza WHO akazarura (addressee) uye RINI (Date / Time). pachena, hazvizo- “guessing”, tinoziva ndiani asvinudza email, atrelamos nekuti date aya URL chifananidzo kana vakatumira.

drawback
Kuti izvi basa, anenge hako vanofanira configured kuitira kuti neindaneti yenyu kuverenga HTML pamanyorerwo, kunyange iri kare mureza akadikamwa vazhinji vanoshandisa. At vakaipisisa, e-mail Provider kuchaita kuratidza shoko vachiti makavhara mifananidzo, asi vachibvunza kana inodzidzisa achida kuratidza, iro Kazhinji kugamuchirwa, sezvo vanhu vashoma ona utsinye mune tsika iyi. Muna Google nyaya, shoko rinowanikwa muchimiro vang, saka:

1
2
3
...
  kwete kuratidza mifananidzo - Budisa mifananidzo pazasi - Nguva dzose zvinoratidza suport mifananidzo@Email.Microsoft.ne
...

Ndichaita vataure maviri nzira kuita izvi; vose kushanda zvakafanana, uye yechipiri zvinonyanya akangwara kwete vanoratidza umboo ari URL, kunyange inoda zvakawanda okuchengetera mamiriro. Uyai!

mhinduro 1

uchidzidzira
Unofanira chete PHP Codes maviri:
(1) mumwe kutumira e-mail HTML pamanyorerwo pamwe pakuvara IMG Tag
(2) uye mumwe kuti andobata mashoko panguva email kuzarurwa

STEP 1 – Email

sendmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?PHP
  // *** Your e (tsambambozha yatumira)
  $remetente_nome     = 'Anonymous';
  $remetente_email    = 'Anonimo@email.com';
 
  // *** kwenyu chipfuro (E-mail kuti yatumira) 
  $destinatario_nome  = 'MarioBross';
  $destinatario_email = 'Mariobross@email.com';
 
  // *** Subject uye shoko muviri
  $chidzidzo      = 'Kuedza manyorero aurayiwe kuti mutoro mufananidzo.';
  $mashoko     = '
    <html lang="pt-br">
      <musoro>
        <meta charset="iso-8859-1" />    
        <musoro wenyaya>'.$chidzidzo.'</musoro wenyaya>
      </musoro>
      <muviri>
        <img src="http://seuservidor.com/script.php?e = '.urlencode($destinatario_email).'&chipfuro = '.urlencode($destinatario_nome).'&Subject = '.urlencode($chidzidzo).'" />
      </muviri>
    </HTML>';
 
  // Header achitaura kuti kugutsikana kunobva mhando HTML (kuti kukwanisa kuverenga IMG Tag uye kumhanya manyorero)
  $Header       = "MIME-Version: 1.0\n"; 
  $Header      .= "Content-type: chinyorwa / HTML; charset = ISO-8859-1\n"; 
  $Header      .= "From: ".(zviri($remetente_nome) ? $remetente_email : '"'.$remetente_nome.'" <'.$remetente_email.'>')."\n";
 
  // Tumira e-mail
  $Email = zviri($destinatario_nome) ? $destinatario_email : '"'.$destinatario_nome.'" <'.$destinatario_email.'>';
  tsamba($Email, $chidzidzo, $mashoko, $Header);
?>

STEP 2 – tora mashoko

tsime, ukacherechedza kuti pakuverenga Tag IMG kudanwa vachaitwa kuti faira “script.php”, zvimwe? Então agora temos que criá-lo para pegar as informações e armazená-las, de preferência num banco de dados.

Criando TABELA
Já que precisamos persistir os dados do destinatário que abriu o e-mail, podemos criar uma tabela como esta abaixo. Veja o campo `datahora_visualizado`, que refere-se última data e hora em que o usuário visualizou o e-mail e o campo `contador`, que irá registrar a quantidade de vezes que o e-mail foi visto.

maladireta.sql
1
2
3
4
5
6
7
8
9
CREATE TABLE  `maladireta` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `email` VARCHAR( 100 ),
  `destinatario` VARCHAR( 100 ),
  `assunto` VARCHAR( 200 ),
  `datahora_envio` DATETIME NOT NULL,
  `datahora_visualizado` DATETIME,
  `contador` INT DEFAULT 0
) ENGINE = MYISAM ;

Script akakunda ruzivo uye kuratidza chifananidzo
kuzviuraya, ngatitorei mashoko sezvo e-mail, zita mugashiri raMwari, nyaya shoko uye musi / nguva uyo akazarura email, yokuchengeta nayo Database takasikwa, ramangwana kana tichida kuti Statistical. No chokupedzisira itai manyorero, Chaizvoizvo kuumba uye kuratidza chifananidzo, chete kwete kuwana chipepa pamwe IMG tsika dambudziko :), asi kana uchida kuratidza chinhu, sika kanenge imwe PaShona mufananidzo (1×1 Pixel) kwete kuti kuputswa Tag.

script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?PHP
  // Initializes uye Pazvibato chiyamuro parameters
  $destinatario_email = kudimburira(strip_tags(addslashes($_REQUEST['E'])));
  $destinatario_nome  = kudimburira(strip_tags(addslashes($_REQUEST['Ndakaitirwa'])));
  $chidzidzo            = kudimburira(strip_tags(addslashes($_REQUEST['Subject'])));       
 
  // Chinobatanidza kuti Database (KUCHINJA Connection RAKO)
  $batanidzo = mysql_connect('Mysql.seuservidor.com', 'Mudzi', 'MyPassword *** ***') kana ari('Chakundikana kubatanidza kuti Database.'); 
  mysql_select_db('seubancodedados') kana ari('Falhou ao selecionar o banco de dados');
 
  // Monta a SQL e insere no banco de dados, caso email ainda não exista, ou atualiza contador se existir
  $sql = 'SELECT email FROM maladireta WHERE email="'.$destinatario_email.'"';
  $res = mysql_query($sql);
  kana (mysql_num_rows($res) > 0) {
    $sql = 'UPDATE maladireta SET datahora_visualizado="'.date('Y-m-d H:i:s').'", contador=contador+1 WHERE email="'.$destinatario_email.'"';    
  }
  else {
    $sql = 'INSERT INTO maladireta VALUES (null, "'.$destinatario_email.'", "'.$destinatario_nome.'", "'.$chidzidzo.'", "'.date('Y-m-d H:i:s').'", null, 0)';
  }
  mysql_query($sql);
 
  // Cria e exibe a imagem embutida ao email
  Header("Content-type: image/png");
  $img = imagecreatefrompng("imagem.png");
  imagepng($img);
  imagedestroy($img);
?>

taura pfungwa: Musakanganwa kuisa pamwe manyorero mufananidzo, hapana nyaya, Ndakadana “imagem.png”. mufananidzo uyu vachaonekwa muviri email wacho wacho, uye ndipo Marketing vanhu vakaisa zvokushambadzira, asi kunogona Logo kana chero zvaunoda. The chinyorwa akaedzwa uye nemabasa!

mhinduro 2

zvimwe
Sezvo pfungwa nevamwe Leandro, mamwe akangwara nezvechisarudzo uye “chengetedzo” wakaramba, pachinzvimbo punching ari URL chifananidzo yakawanda mashoko akadai Email, chidzidzo, nezvimwewo, kusika munhu hashi paakatuma e-mail nokuibatanidza nemashoko ichi, uye kutumira URL chete hashi. Kana mugamuchiri rinovhura email Upload chifananidzo, motokari zvichaita chete hashi zvino achabatwa manyorero yedu uye chokuita Data tinoda kuziva.

Kusika hashi tafura uye linked Data
Isu achasika netafura iri nevakabva nguva dzose isu kutumira e-mail. Cherechedza munda `hash`, izvo richava e-mail kuda kuti akatumwa uye anenge ari mashoko vakanga mudura tafura.

maladireta.sql
1
2
3
4
5
6
7
8
9
10
CREATE TABLE  `maladireta` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `hashi`VARCHAR( 50 ) NOT NULL,
  `email` VARCHAR( 100 ),
  `destinatario` VARCHAR( 100 ),
  `assunto` VARCHAR( 200 ),
  `datahora_envio` DATETIME NOT NULL,
  `datahora_visualizado` DATETIME,
  `contador` INT DEFAULT 0
) ENGINE = MYISAM

Kutumira e-mail

sendmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?PHP
  // *** Your e (tsambambozha yatumira)
  $remetente_nome     = 'Anonymous';
  $remetente_email    = 'Anonimo@email.com';
 
  // *** kwenyu chipfuro (E-mail kuti yatumira) 
  $destinatario_nome  = 'MarioBross';
  $destinatario_email = 'Mariobross@email.com';
 
  // *** Other Data kuramba uye hashi (identifier)
  $hashi               = MD5(Rand());
  $chidzidzo            = 'Kuedza manyorero aurayiwe kuti mutoro mufananidzo.';
  $datahora_envio     = date('Y-m-d H:i:s');
 
  // Chinobatanidza kuti Database
  $batanidzo = mysql_connect('Mysql.seuservidor.com', 'Mudzi', 'MyPassword *** ***') kana ari('Chakundikana kubatanidza kuti Database.'); 
  mysql_select_db('seubancodedados') kana ari('Falhou ao selecionar o banco de dados');  
 
  // Monta a SQL e insere no banco de dados
  $sql = 'INSERT INTO maladireta VALUES (null, "'.$hashi.'", "'.$destinatario_email.'", "'.$destinatario_nome.'", "'.$chidzidzo.'", "'.$datahora_envio.'", null, 0)';
  mysql_query($sql);
 
  // *** Message kutumwa
  $mashoko     = '
    <html lang="pt-br">
      <musoro>
        <meta charset="iso-8859-1" />    
        <musoro wenyaya>'.$chidzidzo.'</musoro wenyaya>
      </musoro>
      <muviri>
        <img src="http://seuservidor.com/script.php?hashi = '.$hashi.'" />
      </muviri>
    </HTML>';
 
  // Header achitaura kuti kugutsikana kunobva mhando HTML (kuti kukwanisa kuverenga IMG Tag uye kumhanya manyorero)
  $Header       = "MIME-Version: 1.0\n"; 
  $Header      .= "Content-type: chinyorwa / HTML; charset = ISO-8859-1\n"; 
  $Header      .= "From: ".(zviri($remetente_nome) ? $remetente_email : '"'.$remetente_nome.'" <'.$remetente_email.'>')."\n";
 
  // Tumira e-mail
  $Email = zviri($destinatario_nome) ? $destinatario_email : '"'.$destinatario_nome.'" <'.$destinatario_email.'>';
  tsamba($Email, $chidzidzo, $mashoko, $Header);
?>

Ona kuti, muchiitiko ichi, mumwe URL (src) mufananidzo chete chete hashi.

Nekurangarira Email akaratidza

script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?PHP
  // Hashi inobudisa E-mail kwakaratidzwa
  $hashi = kudimburira(strip_tags(addslashes($_REQUEST['Hashi'])));
 
  // Chinobatanidza kuti Database
  $batanidzo = mysql_connect('Mysql.seuservidor.com', 'Mudzi', 'MyPassword *** ***') kana ari('Chakundikana kubatanidza kuti Database.'); 
  mysql_select_db('seubancodedados') kana ari('Falhou ao selecionar o banco de dados');
 
  // Monta SQL uye reserved kuona zuva email pakaunda ari Database
  $sql = 'SELECT hash FROM maladireta WHERE hash="'.$hashi.'"';
  $res = mysql_query($sql);
  kana (mysql_num_rows($res) > 0) {
    $sql = 'UPDATE maladireta SET datahora_visualizado="'.date('Y-m-d H:i:s').'", contador=contador+1 WHERE hash="'.$hashi.'"';
    mysql_query($sql);
  }
 
  // Cria e exibe a imagem embutida ao email
  Header("Content-type: image/png");
  $img = imagecreatefrompng("imagem.png");
  imagepng($img);
  imagedestroy($img);
?>

Ah, se você quiser consultar os e-mails que foram visualizados a partir de uma data, poderia fazer um script com uma SQL tipo essa que, hapana nyaya, busca todos os registros recentes de e-mail vistos a partir de 27 Ndira 2013. Fica a dica

1
2
3
4
5
6
7
8
 
  SELECT * 
  FROM 
      `maladireta` 
  WHERE 
      contador > 0 AND 
      DATE(datahora_visualizado) >= DATE("2013-01-27")
;
Uwandu kwakafanorongwa: 34906

8 Wongororo “PHP: Run chinyorwa vachizvitakudza mufananidzo midzi muna e-mail

  1. Leandro Chaves akati:

    Taylor,
    Não é uma boa prática colocar o email do usuário no link da imagem. The akakodzera kuti dzinoisa umboo ari Database panguva kutumira uye akaisa tafura hashi kana ID iri linked, saka sezvo kuziva uyo akazarura email.

    • mhoro Leandro, ngaavongwe nokuti mashoko. Ndizvo debatable. Kufunga ruzivo kuchengeteka uri kurudyi, asi tsika zvaizova zvakanaka unokosha, nokuti NYORA EMAIL (mufananidzo) kuti iwe dzakakosha kudzivirira chete kuwanikwa mune kugamuchira pachake inbox. Ndiko kuti dehwe chinhu kwandiri kuti ndinoziva! Uyezve, iwe aizofanira uchengetedze chigaro chako mumwe tafura nezviuru yamashoko no yako, vasingazivi kana na raiva zvirimo kosha. Zvino kana iwe waida “enchugar” bhangi yako, vakasagona, sezvo panyaya referential kuvimbika pakati matafura, zvaida kuchengeta zvinyorwa, pamusoro nokurwadziwa haana kuziva kuti ndiani asvinudza email. Asi sezvo tiri kutaura pamusoro kuchengeteka, kudzivisa kuva tsambambozha intercepted ne Wireshark upenyu, chii chaigona kuitwa kuti kushandiswa SSL (https) zvose kutumira e, sezvo mufananidzo linked. Asi kufanana kwenyu pfungwa, Ndichaita kubudisa vakadaro mhinduro, vakarumbidzwa!

  2. Ola ,
    Ndiri kutsvaka kuwana IP ari munhu akaverenga mashoko , Zvisinei kana chiri Hotmail nhoroondo Somuenzaniso iye akasarudza ane IP siyana pamwe Domain muna US. rubatsiro Nokudaro zhinji . sei I kuwana IP chaiye muchina wake ?

  3. Régis akati:

    Strange Dzimwe nguva inoshanda uye dzimwe nguva haashandi kushandisa Chrome, Opera E Fire Fox hapana Gmail, e Hotmail – kuchenesa cache uye makeke, asi dzimwe nguva haina kuita kurekodha musi BD kana email wakashamira kana kwete !!

  4. Diego akati:

    Galera..tenho yomuchato manyorero pamwe nome..email…cpf…RG…Ndaida pashure zvose User remazita uye Tumira Database yangu …anodzoka chinhu nokuda kwake tsambambozha automatico..tipo
    MUENZANISO:”ruzivo vakanyorwa zvinobudirira ..” kumirira kuonana kwedu

    Ndinoda??

    • Opa, sezvo Ndakati Post: “Kuti izvi basa, anenge hako vanofanira configured kuitira kuti neindaneti yenyu kuverenga HTML pamanyorerwo”. By default ari HTML rakashandurwa, asi kunyange Gmail uchifamba neshanduro kuti TEXT, ipapo hakushande, nekuti zvichaita nyore kuratidza HTML Tags sezvo chinyorwa pachinzvimbo dzichiti.

Leave a Reply

kero email havazobvumirwi ichibudiswa. Raida minda anozivikanwa ne *