Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

Form mail: User defines recipient in form



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old January 28 '10, 04:02 AM (#1)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
Form mail: User defines recipient in form

Hey i need to setup some sort of form mailer but with one distinct difference. Instead of the recipient being predefined i need something that allows the user to define the recipient of the email in the form itself.

In a nutshell ... the bellows is a example of the form.

Name: Bob
E-mail: Bob@gmail.com (the form results should be mailed to this address)
Text: Random banter!

Help would be greatly appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 28 '10, 08:25 AM (#2)
mlseim is offline
WDF Staff
 
mlseim's Avatar
 
Join Date: April 2004
Location: Cottage Grove, Minnesota
Posts: 3,359
mlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud of
That's easy to do (unless your webhost is GoDaddy).

But ...

What precautions will you take to keep spammers from using your form
to mass email people using your website? That's the problem with doing
what you want to do. It's sort of a dangerous thing that could end-up getting
your webhost to close or suspend your account.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 28 '10, 10:54 AM (#3)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
Thanks for the reply, il sort that out later ... first i would just like to get the thing working. The host is Dataflame. If you could please elaborate how i would go about doing this it would realy help me. I have been searching the web for the entire day and i have come up dry =/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 28 '10, 10:57 AM (#4)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
I thought about using FormMail.pl for this but it turns out that it can only e-mail the form results to e-mail accounts hosted by the server and that dosent help me one bit =/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 28 '10, 12:24 PM (#5)
mlseim is offline
WDF Staff
 
mlseim's Avatar
 
Join Date: April 2004
Location: Cottage Grove, Minnesota
Posts: 3,359
mlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud of
The restriction to email only by account hosted is a function of the webhost.
If Dataflame has that limitation (like GoDaddy), you won't be able to do it with PHP either.

You can test it out though ...

Copy and paste this script as "email.php", and try different recipients ... see what happens:
PHP Code:
<?php

$recipient 
"youremailaddress@aol.com";
$subject "This is an email test";
$sender "whosenttheemail@aol.com";

$content="This is a test to see if you can send an email to anyone.";

$message "
This is an email test
--------------------------------------------------
Email from:  $sender

$content
---------------------------------------------------
"
;

$extraheaders "From: $sender\nReply-To: $sender\n\n";

if (! 
mail($recipient$subject$message$extraheaders))
  echo 
"Mail did not send for some reason.";

echo 
"Email Sent";
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 29 '10, 02:44 AM (#6)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
Much thanks i will give this a try =]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 29 '10, 03:04 AM (#7)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
Ok great that worked =D now what is the nexy step? I really appreciated the help mlseim!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 29 '10, 09:57 AM (#8)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
Ah ok i got something working, this is probebly super bad haha but its my first time working with php.

PHP Code:
<?php

$recipient 
$_POST["recipient"];
$subject "This is an email test";
$sender "salmon@electric-heart.com";
$field1 $_POST["field1"];

$content="This is a test to see if you can send an email to anyone.";

$message "
This is an email test 2 $field1
--------------------------------------------------
Email from:  $sender

$content
---------------------------------------------------
"
;

$extraheaders "From: $sender\nReply-To: $sender\n\n";

if (! 
mail($recipient$subject$message$extraheaders))
  echo 
"Mail did not send for some reason.";

echo 
"Email Sent";
?>
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="mail.php" method="POST" name="contact" id="contact">
   e-mail: <input type="test" name="recipient" value=""><br/>
   first field: <input name="field1" type="text"><br/>
 <input name="Submit" type="submit" value="Submit"></td>

</form>
</body>
</html>
Ok thus far this is working, which i am super happy about haha =D

I need to place some HTML formating and the values from the form in the e-mail that is sent to the recipient. If you could give me a hint of how i would go about this i would realy appreciate it =D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 29 '10, 10:44 AM (#9)
UNarmed is offline
WDF Member
 
UNarmed's Avatar
 
Join Date: September 2008
Posts: 89
UNarmed is on a distinguished road
Ok nevermind i have it all working =] Thanks for giving me the start i needed and all the help!

PHP Code:
<?php
// recipient
$recipient $_POST["recipient"];
// subject
$subject "This is an email test";
$sender "salmon@electric-heart.com";
$field1 $_POST["field1"];

$content="This is a test to see if you can send an email to anyone.";
// message
$message "
<html>
<head>
</head>

</body>
</html>
"
;

// To send HTML mail, the Content-type header must be set
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' "\r\n";

$extraheaders "From: $sender\nReply-To: $sender\n\n";

if (! 
mail($recipient$subject$message$headers))
  echo 
"Mail did not send for some reason.";

echo 
"Email Sent";
?> 
<html>
<body>
<br />First field: <?php echo $_POST["field1"]; ?>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Introducing QiPHP Framework - FINALLY... a Ruby on Rails Killer for PHP!!! smoseley PHP 32 October 14 '09 11:08 PM
PHP Mail Form Mekhet PHP 4 June 10 '08 02:55 AM
mail () form - Customizing for my needs, help! vero PHP 10 December 6 '07 06:27 PM
My mail form causes "Page has Expired" in IE TheGardener PHP 2 March 24 '07 03:04 PM
Mail Form Input Type = Fax? Franco50 General Web Design Discussion 1 October 19 '04 12:26 PM

 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:00 PM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164