Jump to content
php.lv forumi

email no web skripts+forma


ArmandsK

Recommended Posts

Neliels skripts epasta sūtīšanai no web lapas, gan jau kādam noderēs :)

<?php
function show_form()
{
?>

<form action="" method="post">
<p align="left"><strong>Vārds</strong>*<br>
 <input type="text" name="name" size="40" />
</p>
<p align="left"><strong>Jūsu e-pasts</strong>*<br>
<input type="text" name="email" size="40"></p>
<p align="left"><strong>Tēma</strong><br>
<input type="text" name="title" size="40"></p>
<p align="left"><strong>Ziņojums</strong>*<br>
<textarea rows="10" name="mess" cols="50"></textarea></p>

<p align="left"><input type="submit" value="Sūtīt" name="submit"></p>
</form>
*<strong>obligāti aizpildāmie lauki </strong>

<?
}

function complete_mail() {
$_POST['title'] = substr(htmlspecialchars(trim($_POST['title'])), 0, 1000);
$_POST['mess'] = substr(htmlspecialchars(trim($_POST['mess'])), 0, 1000000);
$_POST['name'] = substr(htmlspecialchars(trim($_POST['name'])), 0, 30);
$_POST['email'] = substr(htmlspecialchars(trim($_POST['email'])), 0, 50);

if (empty($_POST['name']))
output_err(0);

if(!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $_POST['email']))
output_err(1);

if(empty($_POST['mess']))
output_err(2);

$mess = '
Sūtītāja vārds:'.$_POST['name'].'

Sūtītāja e-pasts:'.$_POST['email'].'
Ziņojums:'.$_POST['mess'];

$to = '[email protected]';

$from='juus';
mail($to, $_POST['title'], $mess, "From:".$from);

echo '<br><strong>Paldies! Jūsu vēstule nosūtīta.</strong>';
}

function output_err($num)
{
$err[0] = 'kļūda! Nepareizs vārds.';
$err[1] = 'kļūda! Nepareizs e-pasts.';
$err[2] = 'kļūda! Nepareizs ziņojums.';

echo '<p>'.$err[$num].'</p>';
show_form();
exit();
}

if (!empty($_POST['submit'])) complete_mail();
else show_form();
?>

Edited by ArmandsK
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Uz manu mailu nemaz neatnāks, jo regex nepareizs.

Šis it kā pareizāks:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-zA-Z]{2}|com|org|net|edu|gov|mil|int|biz|info|mobi|name|aero|asia|jobs|museum)\b

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...