Sending an email

in HTML or PHP

Page 1 of 1

11 Replies - 1561 Views - Last Post: 29 January 2008 - 07:29 PM

#1 aj32  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 30
  • View blog
  • Posts: 577
  • Joined: 30-August 07

Sending an email

Post icon  Posted 26 January 2008 - 06:08 PM

Hi all! :)

I need a way to make a web page send an email to me automatically, when the user clicks on the submit button or "Send Email" button. I want to be able to set the title and message body of the message. I do not know if you have to be able to get the email address from the user first, but I would prefer that you wouldn't have to. If it does, could I have the sender address be set as one of my other email addresses? I want it to be in either HTML, Javascript, or PHP.

-Thank you for your help! :D

Is This A Good Question/Topic? 0
  • +

Replies To: Sending an email

#2 Mike007  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

Re: Sending an email

Posted 26 January 2008 - 06:44 PM

Well you can try this:
<form action="mailto:your@email.address" method="POST"  enctype="text/plain">
	<input type="text" value="Something1"  name="field1"/>
	<input type="text" value="Something2"  name="field2"/>
	<input type="text" value="Something3"  name="field3"/>
	<input type="submit" value="send" />
</form>



But, it has way too many downsides, doinging something like that with html+javascript. First it is too dependend on the browser itself and the mailing system it employes, so it is not certain that you will actually get the mail or get all the information. Second, most browsers notify the user about it and may alarm the user and make him reconsider sending the mail. And third, think of the spam and what not you can get like that from some users.

It only make sense that you do it all using PHP, send the form, check it, and mail it to your email address.

As for how to do it with PHP, i'm not exactly sure, never sent a mail using PHP yet. But I'm sure if you google it you will find what you need.
Was This Post Helpful? 0
  • +
  • -

#3 aj32  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 30
  • View blog
  • Posts: 577
  • Joined: 30-August 07

Re: Sending an email

Posted 26 January 2008 - 06:55 PM

That way opens up outlook or another email client, I want the message just to be sent without the user editing it (If this is possible!)

Thanks! :)
Was This Post Helpful? 0
  • +
  • -

#4 fahlyn  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 03-November 07

Re: Sending an email

Posted 26 January 2008 - 07:33 PM

you cannot do that with javascript, html or css...you'll need to use php. See this for more details.
Was This Post Helpful? 0
  • +
  • -

#5 Mike007  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

Re: Sending an email

Posted 26 January 2008 - 07:48 PM

View Postfahlyn, on 26 Jan, 2008 - 07:33 PM, said:

you cannot do that with javascript, html or css...you'll need to use php. See this for more details.


Also we have a tutorial right here on dreamincode.net that shows another way of doing this instead of using the mail function: http://www.dreaminco...wtopic36108.htm
Was This Post Helpful? 0
  • +
  • -

#6 aj32  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 30
  • View blog
  • Posts: 577
  • Joined: 30-August 07

Re: Sending an email

Posted 26 January 2008 - 08:32 PM

View PostMike007, on 26 Jan, 2008 - 09:48 PM, said:

View Postfahlyn, on 26 Jan, 2008 - 07:33 PM, said:

you cannot do that with javascript, html or css...you'll need to use php. See this for more details.


Also we have a tutorial right here on dreamincode.net that shows another way of doing this instead of using the mail function: http://www.dreaminco...wtopic36108.htm


Yeh, I saw that right after posting the topic :rolleyes: !

One thing though, (this may be a stupid question, but) can you put php code into an html file, and if you can, what part of it(<body>, <head>, ect...). (I've haven't used php yet)

Thanx :)
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5316
  • View blog
  • Posts: 27,221
  • Joined: 10-May 07

Re: Sending an email

Posted 26 January 2008 - 08:36 PM

View Postaj32, on 26 Jan, 2008 - 08:32 PM, said:

View PostMike007, on 26 Jan, 2008 - 09:48 PM, said:

View Postfahlyn, on 26 Jan, 2008 - 07:33 PM, said:

you cannot do that with javascript, html or css...you'll need to use php. See this for more details.


Also we have a tutorial right here on dreamincode.net that shows another way of doing this instead of using the mail function: http://www.dreaminco...wtopic36108.htm


Yeh, I saw that right after posting the topic :rolleyes: !

One thing though, (this may be a stupid question, but) can you put php code into an html file, and if you can, what part of it(<body>, <head>, ect...). (I've haven't used php yet)

Thanx :)

You put it between <?php & ?> tags.
Was This Post Helpful? 0
  • +
  • -

#8 andrewvw  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-January 08

Re: Sending an email

Posted 29 January 2008 - 12:16 AM

Dont know if u have wat u were lookin for already but heres wat i use

first of all u put this in the body section of your code

<form method="post" action="nameofscriptfile.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>



in a separate file
name it wat you put in action=""

<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "yourname@example.com", "Message Subject",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
?>

if something doesnt work tell me i was in a hurry i probably didnt put something corectly
Was This Post Helpful? 0
  • +
  • -

#9 aj32  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 30
  • View blog
  • Posts: 577
  • Joined: 30-August 07

Re: Sending an email

Posted 29 January 2008 - 01:50 PM

That code seems to be opening the php file with the browser like a text file.

Thanks
Was This Post Helpful? 0
  • +
  • -

#10 andrewvw  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-January 08

Re: Sending an email

Posted 29 January 2008 - 06:02 PM

does ur host support php?
here i made a preview on my website
andrewvworld.com/1.html


Why doesnt html work here lol i tried putting a frame
Was This Post Helpful? 0
  • +
  • -

#11 aj32  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 30
  • View blog
  • Posts: 577
  • Joined: 30-August 07

Re: Sending an email

Posted 29 January 2008 - 06:07 PM

Quote

does ur host support php?

Oh, yea, DUH, I forgot to upload it to my server... I was trying to run it from my computer! lol!

Thanks...

This post has been edited by aj32: 29 January 2008 - 06:07 PM

Was This Post Helpful? 0
  • +
  • -

#12 andrewvw  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-January 08

Re: Sending an email

Posted 29 January 2008 - 07:29 PM

lol yea that might help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1