Jump to content
php.lv forumi

epasts


mirstigais

Recommended Posts

jau labu laiku mēģinu saprast kļūdu, bet nekā, googlē arī pētu, bet cik izskatās

 

if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {echo "Nav ievadīta reāla e-pasta adrese. Mēģini vēlreiz."; }

else {

 

šajā rindiņā nav kļūdas, bet kad noņemu tad viss aiziet, līdz ar to nesaprotu kur ir kļūda. Tādēļ varbūt kāds var pateikt kur kļūda?

 

<?

$name=$_POST['name'];

$email=$_POST['email'];

$feedback=$_POST['feedback'];

 

$name=trim($name);

$email=trim($email);

$feedback=trim($feedback);

 

if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {echo "Nav ievadīta reāla e-pasta adrese. Mēģini vēlreiz."; }

else {

 

 

$toaddress = "epasts@epasts.lv";

 

$subject = "No Weblapas";

$mailcontent = "Vārds: ".$name."\n"

."E-pasts: ".$toaddress."\n"

."Komentārs: \n".$feedback."\n";

$fromaddress = $toaddress;

 

mail($toaddress, $subject, $mailcontent, "From: $fromaddress");

?>

<html>

<head>

<title>E-pasts nosūtīts</title>

</head>

<body>

<h1>E-pasts nosūtīts</h1>

<p>Vēstule ar sekojošu saturu ir nosūtīta <? echo $toaddress; ?>:</p>

<p><? echo nl2br($mailcontent); } ?> </p>

 

</body>

</html>

Edited by mirstigais
Link to comment
Share on other sites

Mēģini...

 

"/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/"

 

...uz:

 

'/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/'

 

Redzi, tā kā tiek izmantotas dubultās pēdiņas interpretators domā, ka "\" ir kā "escape character".

Link to comment
Share on other sites

Man sāk likties ka google interfeiss ir pārlieku sarežģīts.

 

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b

^(([a-zA-Z0-9\._-]+)@([a-zA-Z0-9-]+)\.([a-zA-Z]{2,4}))$

^[\w\d\|~&\+\-/%=_!#\$\^{}`\+\?\*]([\w\d\|~&\+\-/%=_!#\$\^{}`\.\+\?\*]*[\w\d\|~&\+\-/%=_!#\$\^{}`\+\?\*])?(@)[\w\d]([\w\d\.]*[\w\d\.])?(com|se|org|nu|net)$

^[a-z0-9]+(?:[-\._]?[a-z0-9]+)*@(?:[a-z0-9]+(?:-?[a-z0-9]+)*\.)+[a-z]+$

^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)+)@(([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)){2,}\.([A-Za-z]){2,4}+$

^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$

^(?:\\w+\(\.|-)+)*\\w+@(?:\\w+\(\.|-)+)*\\w+\\.\\w+$

[a-zA-Z0-9._-]+@[a-zA-Z0-9]+.[a-z]+(.[a-z]+)?

\b[!#\$%&'\*\+\-/=\?\^_`{\|}~a-zA-Z0-9][!#\$%&'\*\+\-/=\?\^_`{\|}~a-zA-Z0-9\.]*[!#\$%&'\*\+\-/=\?\^_`{\|}~a-zA-Z0-9]@[a-zA-Z0-9\-][a-zA-Z0-9\-\.]+[a-zA-Z0-9\-]\b

Link to comment
Share on other sites

Pēdējo reiz kad meklēju labu epasta filtru es uzdūros kādam rakstam kur tika apkopoti dažādi pasaules standarti filtrējot pareizās epasta adrese, ka arī to uzlabojumi. Tā kā e-pasta adreses var būt ar ip adresēm un vēl dažnedažākajiem veidiem, tad īstenībā lai visus veidus atrastu nepieciešams nežēlīgi garš koda gabals, kurš diemžēl arī pat tad nespēja atfiltrēt visas reālās adreses. Vai maz eksistē tāds universāls filtrs?

Link to comment
Share on other sites

http://www.w3.org/Protocols/rfc822/

$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom  = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$pair  = '\\x5c[\\x00-\\x7f]';

$domain_literal = "\\x5b($dtext|$pair)*\\x5d";
$quoted_string  = "\\x22($qtext|$pair)*\\x22";
$sub_domain     = "($atom|$domain_literal)";
$word           = "($atom|$quoted_string)";
$domain         = "$sub_domain(\\x2e$sub_domain)*";
$local_part     = "$word(\\x2e$word)*";

$expression     = "/^$local_part\\x40$domain$/D";

return (bool)preg_match($expression, (string)$email);

Link to comment
Share on other sites

Nav sanācis pašam ar šiem darboties, bet var izmantot PHP iebūvētās funkcijas

filter_var($email, FILTER_VALIDATE_EMAIL)

 

Pēdējā laikā ar šo variantu lietoju. Strādā bez problēmām.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...