It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum Script-archive

Send an email from you website

Share your completed scripts.

Moderator: Malcolm

Send an email from you website

Postby flabbyrabbit on Mon Dec 24, 2007 12:11 pm

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);
?>[/php]
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: Select all
<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";
?>[/php]
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
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby anonymousnewbie on Mon Dec 31, 2007 9:02 pm

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?
anonymousnewbie
 
Posts: 4
Joined: Mon Dec 10, 2007 3:53 am

Postby Johnathan on Tue Jan 01, 2008 10:27 pm

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.
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby DDragon on Wed Feb 20, 2008 2:53 am

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
DDragon
50+ Club
 
Posts: 93
Joined: Wed Jun 20, 2007 12:51 am
Location: Australia

Postby webmaster on Wed Feb 20, 2008 8:42 am

The only changes in the PHP-script you'll have to do is to change the e-mail in:
$to ='nosmo-kings@hotmail.com';
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby leonard on Wed Mar 12, 2008 1:50 pm

If you don't want your emails to be marked as spam when they are received, you may want to have a look at this topic:

how-to-avoid-being-spam-vt9653.html

cheers!
- leonard
:%s/^M//
There are 10 kinds of people:
Those who understand binary and those who don't.
User avatar
leonard
100+ Club
 
Posts: 147
Joined: Tue Dec 18, 2007 7:11 am
Location: Switzerland

Postby DDragon on Sat Jun 14, 2008 4:20 am

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
DDragon
50+ Club
 
Posts: 93
Joined: Wed Jun 20, 2007 12:51 am
Location: Australia

Postby Johnathan on Sat Jun 14, 2008 9:47 am

You need to put all the individual fields into the script. Well the ones you want to get from your user....
Last edited by Johnathan on Wed Oct 22, 2008 9:29 pm, edited 1 time in total.
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby DDragon on Sat Jun 14, 2008 10:59 am

lol ok now i see *points to self* learn to friggen read sip**** lol
thanks john
DDragon
50+ Club
 
Posts: 93
Joined: Wed Jun 20, 2007 12:51 am
Location: Australia

Re: Send an email from you website

Postby niz972 on Wed Jun 10, 2009 7:36 pm

Hey all! Trying to use this as a "Send this page to a friend" script so that it included the website link in the message. How would I go about doing this? Thanks in advance!
niz972
 
Posts: 1
Joined: Wed Jun 10, 2009 7:33 pm

Next

Who is online

Users browsing this forum: No registered users and 0 guests