Html form email
Page 1 of 1
dingo_d
VIP Member



Posts: 14555

PostPosted: Tue, 13th Jul 2010 15:07    Post subject: Html form email
So I'm doodling with my site again (I'm bored and I need to wait for my parents to come back from vacation for new comp -.-) and I made an email form so that ppl who come to my site can write how awesome I am grinhurt

Anywho... I made the form and it works, but when I tested the email submission (I clicked send button) the site opened outlook for that and I would like that it would just send mail without the need of outlook.

I have jquery involved and I read that you can do that in php (sending without outlook), but my site is just plain html+css+jquery.

code is:

Code:
   <form action="imnotgivingyou@my.mail.adress" method="post">
                  
                  <label>Your Name <span>(Required)</span></label>
                  <span class="field"><input type="text" name="" value="" /></span>
                  
                  <label>Your E-Mail <span>(Required)</span></label>
                  <span class="field"><input type="text" name="" value="" /></span>
                  
                  <label>Message <span>(Required)</span></label>
                  <span class="textarea-field"><textarea name="" rows="6" cols="10"></textarea></span>
                  
                  <input type="submit" class="submit" value="Submit">
               </form>


Can that be done via jquery?


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
DarkPassenger




Posts: 1171

PostPosted: Tue, 13th Jul 2010 15:15    Post subject:
Hmm, I'm quite sure you need a server-side language for that (php for example). And a POP server of course.

It opens outlook because the 'action' is an email address, and when you click send whatever default mail programme you have tries to open it.
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Tue, 13th Jul 2010 15:41    Post subject:
No, you can't do that with just HTML+CSS+JS. Reason is simple: all three are client-side, and as such you're not allowed to use their computer to send emails. You'll have to use a server-side language to handle this; anything will do, PHP, PERL, ASP, Ruby.

It's best to use a library to do that, for PHP I suggest PHPMailer. Just make sure to download the appropriate version, i.e. php5/6 or php4 Smile
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Tue, 13th Jul 2010 16:10    Post subject:
So I just put php code in my index.html instead of this and I should be alright?


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
garus
VIP Member



Posts: 34200

PostPosted: Tue, 13th Jul 2010 16:11    Post subject:
snip


Last edited by garus on Tue, 27th Aug 2024 21:27; edited 1 time in total
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Tue, 13th Jul 2010 16:32    Post subject:
So I make just those two (form.html and send.php) and include them somehow? I'm a bad coder Sad


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Tue, 13th Jul 2010 16:40    Post subject:
No, the "action" parameter from your form POSTs the data to send.php, no need for any includes. Just create the files, and you're done Smile

Quick warning by the way, this way allows spamming by hitting F5 Razz
Back to top
garus
VIP Member



Posts: 34200

PostPosted: Tue, 13th Jul 2010 16:42    Post subject:
snip


Last edited by garus on Tue, 27th Aug 2024 21:27; edited 1 time in total
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Tue, 13th Jul 2010 16:49    Post subject:
garus wrote:
Yeah, well. It needs adjustments but that's up to you, depending on how popular your site is Razz


Well ppl go there to get various ebooks so I wouldn't want unnecessary mail :\

I'll see it out Very Happy Thanks guys ^^


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Tue, 13th Jul 2010 17:04    Post subject:
Well then better adjust the script to make it more secure Laughing


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Tue, 13th Jul 2010 19:21    Post subject:
EDIT: I found this:

Code:
<?php
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid input";
    }
  else
    {//send email
    $email = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
    mail("someone@example.com", "Subject: $subject",
    $message, "From: $email" );
    echo "Thank you for using our mail form";
    }
  }
else
  {//if "email" is not filled out, display the form
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>


So I save that as send.php put it into my public.html and how to incorporate that into that form I gave? As garus said?

EDIT2: Ok so it works, but I deleted that last part (don't know what that mailform.php does or where to get it grinhurt).

EDIT3:

So my final code is this:

Code:
<?php
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Krivi unos!";
    }
  else
    {//send email
    $email = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
    mail("xxx@x.x.x", "Subject: $subject",
    $message, "From: $email" );
    echo "Hvala sto koristite moj e-mail formular ^^";
    echo "<meta http-equiv='refresh' content='=5; index.html' />";
    }
  }
?>


The last echo will get me back from the Thank you note in Cro Very Happy But I would like that the page would be visible for at least 5 sec, this just blinks... Do I increase content number or?


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.


Last edited by dingo_d on Tue, 13th Jul 2010 19:48; edited 1 time in total
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Tue, 13th Jul 2010 19:47    Post subject:
Erm that code above is mailform.php Very Happy
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Tue, 13th Jul 2010 19:50    Post subject:
oh... grinhurt lol what does it do? I mean that last part? I named it send.php, so I would just need to put instead mailform.php send.php, right?

But what does that do? It will shout sth (I guess with echo...)


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Tue, 13th Jul 2010 20:03    Post subject:
Basically it checks if there's an email in the POST values, verifies that and sends an email, and if there's no email in the POST values it displays the form.

You should take a crash course in PHP, tons of tutorials out there, and it's easy to pick up Smile
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group