| View previous topic :: View next topic |
| Author |
Message |
flabbyrabbit 500+ Club

Joined: 25 Jan 2007 Posts: 567 Location: UK
|
Posted: Mon Dec 24, 2007 1:11 pm Post subject: Send an email from you website |
|
|
This question has been ask so often, so here it is.
Simple mail function, send a flat email.
| PHP: |
<?php
$to = 'to@hotmail.com'; //address email should be sent to
$subject = 'subject here'; //Subject of the email
$message = 'enter the message here'; //The message
//These extra headers allow you to set who the message is from
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//"From" is address that the email would have been sent from
//"Reply-To" is the address that any replies will be sent to
//This line sends your message
mail($to, $subject, $message, $headers);
?>
|
This wont be very useful to most people, as it is very rarely you want to sent the same email to one person repeatedly.
So next i will show you how to create a form that will be used to send the email. I this example i will use a contact form on a web page that allows visitors to send a message to the owner.
First create a page called contact.php, then enter this code:
| Code: |
<form method=POST action="send.php">
Email: <input name="email"><br>
Subject: <input name="subject"><br>
Message:<br>
<textarea name="message" cols=40 rows=6></textarea><br>
<input type=submit value="send">
</form> |
Then make another page called send.php:
| PHP: |
<?php
$to ='nosmo-kings@hotmail.com'; //Your email address (webmasters email address)
$subject = $_POST['subject']; //Gets the subject sent by the form
$message = $_POST['message']; //Gets the message sent by the form
$headers = 'From: ' . $_POST["email"] . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//Changes the reply to email so the webmaster can easily reply
mail($to, $subject, $message, $headers);
//Shows a message when email is sent
echo "message sent";
?>
|
Now the contact form should be up and running. Emails may be placed in recipients junk mail box for security reasons.
I hope this answers everyones questions, but if you need any more help don't hesitate to ask,
Flabby Rabbit |
|
| Back to top |
|
 |
|
|
anonymousnewbie
Joined: 10 Dec 2007 Posts: 4
|
Posted: Mon Dec 31, 2007 10:02 pm Post subject: Re: Send an email from you website |
|
|
i think I'm too stupid..
may i know what is the good start for me to learn any basic programming language...do i need to download or installed it?can we start with notepad?i make a research that notepad can save to certain program like .vbs, .bat.
is any other? |
|
| Back to top |
|
 |
Johnathan 500+ Club

Joined: 31 May 2007 Posts: 916 Location: Belfast, Northen Ireland
|
Posted: Tue Jan 01, 2008 11:27 pm Post subject: Re: Send an email from you website |
|
|
| Yea you can use notepad. Save it as .php the way you save the other stuff in different formats like .html, .vbs and so on. |
|
| Back to top |
|
 |
DDragon 50+ Club
Joined: 20 Jun 2007 Posts: 90 Location: Australia
|
Posted: Wed Feb 20, 2008 3:53 am Post subject: Re: Send an email from you website |
|
|
ok. i have tried this out and have not got it working properly. with the 'contact.php' is there any php scripting needed? as i am new to PHP scripting and am not sure what to do with it.
Thanks DD |
|
| Back to top |
|
 |
webmaster Site Admin

Joined: 17 Aug 2004 Posts: 3612 Location: Sweden
|
Posted: Wed Feb 20, 2008 9:42 am Post subject: Re: Send an email from you website |
|
|
The only changes in the PHP-script you'll have to do is to change the e-mail in:
$to ='nosmo-kings@hotmail.com'; |
|
| Back to top |
|
 |
leonard 100+ Club

Joined: 18 Dec 2007 Posts: 147 Location: Switzerland
|
|
| Back to top |
|
 |
DDragon 50+ Club
Joined: 20 Jun 2007 Posts: 90 Location: Australia
|
Posted: Sat Jun 14, 2008 5:20 am Post subject: Re: Send an email from you website |
|
|
Ok i have a large form i need this script for. DO i have to input each individual field into the script or will it take all fields into the message and send as is?
DD |
|
| Back to top |
|
 |
Johnathan 500+ Club

Joined: 31 May 2007 Posts: 916 Location: Belfast, Northen Ireland
|
Posted: Sat Jun 14, 2008 10:47 am Post subject: Re: Send an email from you website |
|
|
| You need to put all the individual fields into the script. Well the ones you want to get from your user... |
|
| Back to top |
|
 |
DDragon 50+ Club
Joined: 20 Jun 2007 Posts: 90 Location: Australia
|
Posted: Sat Jun 14, 2008 11:59 am Post subject: Re: Send an email from you website |
|
|
lol ok now i see *points to self* learn to friggen read sip**** lol
thanks john |
|
| Back to top |
|
 |
|