Email form - Must contain e.g.

Hey there,

We´re using a simple email form at my job.
Quite often the employees write the wrong email address, eg. [email protected] instead of [email protected].

Is it possible to force the users to always write ?

Also I would like to give them an error if they write a blank space after their email, which also happens quite often… eg. "[email protected] " instead of [email protected]"

Thanks in advance!

If this is internal so everyone would use "[email protected]" I would do

  1. if the user fills out a form to have an email sent to him he shouldn’t need to fill out his email address, the system should know it.

  2. if the user wish to email someone else, create an ajax search box where the employee can search for other employees

So if he types in “Ji”, It would suggest:
Jim Leirvik [email protected]
Jim Parsons [email protected]


If it’s mixed (can send to gmail/hotmail/examplemail/etc) then it gets more tricky.

  1. If most mails are going to then have a text field for username and a dropdown pre-selected to, so it would be like
    Email: [ ] []

If the user selects “other” then use ajax to remove the drop-down and expand the email-field

  1. if you need to control other mis-typings as well you would need to do a lookup, so before submitting check if you have the value in your “typo-table”, if so ask the user to confirm he really wants to send to the entered email address.


It´s internal so we always use the same domain-name in the FROM field.
And it sends the email to a static e-mail address, which they aren´t able to choose.

So it´s the FROM field i´d like to fix.
But I have no idea how to make the form know which user that´s going to fill the email.

Can you put me in the right direction?

Here´s my form, I hope it´s not too messy for you. :-[

if (isset($_POST[“submit_trigger”])) {


$emailaddress = ‘[email protected]’;

$first_name = $_POST['first_name']; 
$datum = $_POST['datum'];
$kundnamn = $_POST['kundnamn'];
$email = $_POST['email'];
$agentmail = $_POST['agentmail'];
$telephone = $_POST['telephone'];
$objnr = $_POST['objnr'];
$typ = $_POST['typ'];
$comments = $_POST['comments'];


Ni har fått ett ärende från Kundtjänst.
Se nedan.

Handläggare: ". $first_name . "
Datum/tid: ". $datum . "
Kundens uppgifter
Namn ". $kundnamn . "
Telefonnummer ". $telephone . "
Mailadress ". $email . "
ObjektID/Serienummer ". $objnr . "
Typ av ärende ". $typ . "

Eventuell kommentar:
". $comments . "


$mail = new PHPMailer();
$mail->Host = “xxx”;

$mail->SMTPAuth = true;
$mail->Host = “xx”;
$mail->Port = xx;
$mail->Username = “xx”;
$mail->Password = “xx”;

$mail->CharSet = ‘UTF-8’;


$mail->Subject = “subjeeeect”;


$validAttachments = array();
foreach($_FILES[‘fileAttach’][‘name’] as $index => $fileName)
$filePath = $_FILES[‘fileAttach’][‘tmp_name’][$index];
$attachment = new stdClass;
$attachment->fileName = $fileName;
$attachment->filePath = $filePath;
$validAttachments[] = $attachment;
foreach($validAttachments as $attachment)
$mail->AddAttachment($attachment->filePath, $attachment->fileName);


if(!$mail->Send()) {
echo “

Meddelandet skickades inte!
” . $mail->ErrorInfo . “
Kontakta Robert Eliasson.

} else {

echo “

Meddelandet skickat!



<? } ?> html, body {margin: 0px; padding: 0px; background: #B3D9FF;} label {font-weight: normal; width: 140px; display: inline-block; padding: 3px;} .success_message, .error_message {display: inline-block; padding: 2px 5px; font-weight: bold; margin-bottom: 5px;} .success_message {background: #A9F5AB;} .error_message {background: #FF8080;} #main_container {width: 800px; -moz-border-radius: 5px; margin: 0px auto; padding: 0px; float:left;} .FormStyleknapp{ width: 130px; height: 40px; margin:1px; border-style: solid; -moz-border-radius: 5px; -webkit-border-radius: 5px; color:#ffffff; border-width: 0px; background-color: #ed2724; button:hover{background-color:rgba(255,204,0,0.8);}

width: 130px;
height: 40px;
border-style: solid;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-width: 0px;
background-color: #ed2724;


Bra att tänka på…

Att ta emot en felanmälan skiljer sig mot ett ”vanligt” kundtjänst samtal

på så sätt att när kund ringer är de ofta irriterade eller missnöjda.

Man ska inte gå in i en diskussion med kund om olika saker utan bäst är att med ett korrekt och trevligt sätt ta emot en felanmälan eller beställning.

Uppgifter som serviceavdelningen måste ha för att kunna utföra ett bra arbete är…

Lova ej att en tekniker ska komma till kund vid en speciell tidpunkt.

<?php echo $posting_message; ?>
Datum/tid <? date_default_timezone_set('Europe/Stockholm'); ?> kl.<?php echo date("H:i") . ""?>">
Handläggare *
Mailadress *
Kundens uppgifter
Namn *
Telefonnummer *
Objekt ID / Serienummer * Maskinen är märkt med en klisterlapp där det tydligt står en bokstav följt av fyra siffror, exempelvis B1415. OBS! De kunder som anger ett objektID som börjar på BU har inget serviceavtal och hanteras av kundtjänst. Hänvisa reklamationer till tillverkaren.

Typ av ärende * Felanmälan
Vid felanmälan:
Har maskinen någon felkod?
Står maskinen still?
Dåliga kopior? - Få en beskrivning, t.ex. ränder eller dåliga färger.
Pappersstopp? - Var i maskinen?

Eventuell kommentar


In order to get the users email address the users need to be logged in. If they are it’s just to fetch their email from session/db.

If they are not logged in then I wouldn’t bother going this route. I’d rather do the split field method and do a


This mean they would post only what’s in front of "", so in your server side validation you would have to do

[php]$email = $_POST[‘email’] . ‘’;[/php]

Hmm I´m not sure if this solution is a good idea, the people aren´t very used to computers.
So they will probably write in the domain name anyway and we´ll get even more errors :frowning:

Isn´t there a solution to only allow and get an error if it´s not correctly written?

Sure, just do a strpos to check if it contains and alert if not. Could be done in js as well :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service