php mail() - create required fields and e-mail verification

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alapimba
Forum Newbie
Posts: 3
Joined: Fri May 13, 2005 6:17 am

php mail() - create required fields and e-mail verification

Post by alapimba »

Hello, i'm new to this forum and i have a question that i guess it's very simple but i can't find the answer on the forum so here it is.
I want to verify if none of the fields are blank and also if the user entered a valid mail(xxx@xxx.xxx)
My code so far is this and it's working fine.

Code: Select all

<form name=&quote;form1&quote; method=&quote;post&quote; action=&quote;form_sugestoes.php&quote;>
                                  <span class=&quote;style5&quote;><br>
                                  Nome:</span><br>
                                  <input name=&quote;nome&quote; type=&quote;text&quote; id=&quote;nome&quote; size=&quote;50&quote;>
                                  <br>
                                  <span class=&quote;style5&quote;><br>
                                  E-mail:
                                  </span><br>
                                  <input name=&quote;mail&quote; type=&quote;text&quote; id=&quote;mail&quote; size=&quote;50&quote;>
                                  <br>
                                  <span class=&quote;style5&quote;><br>
                                  Empresa:
                                  </span><br>
                                  <input name=&quote;empresa&quote; type=&quote;text&quote; id=&quote;empresa&quote; required=&quote;required size=&quote;50&quote;>
                                  <br>
                                  <span class=&quote;style5&quote;><br>
                                  Sugestão:</span><br>
                                  <textarea name=&quote;mensagem&quote; cols=&quote;38&quote; rows=&quote;5&quote; wrap=&quote;VIRTUAL&quote; id=&quote;mensagem&quote;></textarea>
                                  <br>
                                  <br>
                                  <input type=&quote;submit&quote; name=&quote;Submit&quote; value=&quote;Enviar&quote;>
                                                                                                </form>
and the php code from the file form_sugestoes.php

Code: Select all

<?php
$sendTo = "xxx@hotmail.com";
$subject = "Sugestão sobre site xxx";
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: " . $_POST["nome"];
$headers .= "<" . $_POST["mail"] .">\r\n";
$headers .= "Reply-To: " . $_POST["mail"];

// varaveis
$nome= $_POST["nome"];
$mail= $_POST["mail"];
$empresa= $_POST["empresa"];
$mensagem= $_POST["mensagem"];

/* message */
$message =
"<html>
<head>
 <title>xxx</title>
</head>
<body>
<p><strong>nome:</strong>$nome</p>
<p><strong>mail:</strong>$mail</p>
<p><strong>empresa:</strong>$empresa</p>
<p><strong>mensagem:</strong>$mensagem</p>

</body>
</html>";

mail($sendTo, $subject, $message, $headers);
header("Location: sugestoes_yes.php");
?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: php mail() - create required fields and e-mail verificat

Post by malcolmboston »

alapimba wrote: I want to verify if none of the fields are blank and also if the user entered a valid mail(xxx@xxx.xxx)
as an extension of this, is it possible to make sure an email address actually exists (this is not for spam purposes, i dont even really have a use for it for the moment but thinking for the future..)
alapimba
Forum Newbie
Posts: 3
Joined: Fri May 13, 2005 6:17 am

Post by alapimba »

if theres a chance to verify if the mail really exist that's even better. I just thought it was too hard and wanted the simplest way.
Can you help me?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

alapimba wrote:if theres a chance to verify if the mail really exist that's even better. I just thought it was too hard and wanted the simplest way.
Can you help me?
You can do it, search these forums, its been discussed many times before. The conclusion most threads come to is that it is not 100% accurate. The better way is to send an email with a verification link.

viewtopic.php?t=29067&highlight=check+c ... mail+exist
alapimba
Forum Newbie
Posts: 3
Joined: Fri May 13, 2005 6:17 am

Post by alapimba »

And how can i make some fileds to be required to the form be sent? Can you explain me please?
Post Reply