Help adding confirmation of email '@' symbol to php script

Hi,

I need some code to validate an email address sent on my form.

Does anyone know if its possible to add anything to exsiting code below to do this.

I’m mainly bothered that the email has a ‘@’ symbol, nothing more complex really.

Here’s my code which works fine at the mo:

<?php // Getformdataandcreateemail $Email2="[email protected]"; $email=$_POST['Email']; $name=stripslashes($_POST['Name']); $subject=stripslashes($_POST['Subject']); $messagecont=stripslashes($_POST['Message']); $message= <<

Many thanks for looking

[php]
//Sendemail
if(strpos($Email2,’@’)==false)
{
?>

error U havvent entert a vails email addreses.
Please go back and check ur email address. <?php } elseif(@mail($Email2,$subject,$message, "From:$Email2")) { header("Location:thankyou.html"); } else { ?> error There was an error trying to sent the email.
Pleas try again.
If it happans again pleas contact the side admin. <?php } [/php]

Hi, Thanks for that. I added but it still dont seem to work.

[code]<?php

// Getformdataandcreateemail
$Email2="[email protected]";
$email=$_POST[‘Email’];
$name=stripslashes($_POST[‘Name’]);
$subject=stripslashes($_POST[‘Subject’]);
$messagecont=stripslashes($_POST[‘Message’]);
$message=
<<<EOD

Enquiry from your website

Name: $name
Subject: $subject
EmailAddress: $email
Message: $messagecont


End of Message

EOD;

//Sendemail
if(strpos($Email2,’@’)==false)
{
?>

error U havvent entert a vails email addreses.
Please go back and check ur email address. <?php } elseif(@mail($Email2,$subject,$message, "From:$Email2")) { header("Location:thankyou.html"); } else { ?> error There was an error trying to sent the email.
Pleas try again.
If it happans again pleas contact the side admin. <?php } [/code]

Am I doing something wrong?

lol

if u translate my signature it meen something like:
when u find spelling mistakes u may keep them.

that doesn’t mean that u have to copy and paste them inside ur script.

the code i provided is more or less just an example. try to understand it and u will see that i used the wrong email address to check it, as u used the wrong one to send the mail to.

edit: of cause i ment from, not to.

I sometimes get blank emails from contact form on my site. It happens when users click submit by mistake. My exsiting code doesnt check the fields have any content before sending the form.

I need to add some code to check that fields have been filled out on my form.

Do you know if its possible to add anything to exsiting code to do this.

I’m mainly bothered that the fields just have some text, nothing more complex really.

if u wanna ceep this simple example with the back button u can do that by just modyfying the if statment:

[php]
//Sendemail
if(strpos($email,’@’)==false or empty($_POST[‘Name’]) or empty($_POST[‘Message’]) or …)
{
?>

error U havent filled out all the fields or havn't entert a vails email addreses.
Please go back and check ur email address. <?php } elseif(@mail($Email2,$subject,$message, "From:$email")) { header("Location:thankyou.html"); } else { ?> error There was an error trying to sent the email.
Pleas try again.
If it happans again pleas contact the side admin. <?php } [/php]

or u have to submit the form to the same page do the checking first then send the email or echo out the form again including the already filledin data. in that case u can tell the user on the same page what field is missing (e.g. make the lable red and bold)
there are a lot of exaples on the web, and even inside this forum.

hope this helps

Sponsor our Newsletter | Privacy Policy | Terms of Service