PDA

View Full Version : php question


maximillion
06-28-2011, 06:34 PM
what i am looking to accomplish:

i have a simple form where a user enters their email and clicks submit..

what i need is 1 php file that sends me an email containing their email address.. it doesn't need to give a thank you message or anything, just clear the box after submitting.

it can have like a popup box saying something like "Thank you, your email address has been submitted."

ruletka
06-28-2011, 07:41 PM
<?php
$theiremail = $_REQUEST['email'];
$to = 'youremail@live.com';
$fields = array();
$fields{"email"} = "Email";
$body = "\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %

s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: $theiremail";
$subject2 = "Someone contacted you";
$autoreply = "".$theiremail."";

if($theiremail == '') {print "You have not entered an email, please go

back and try again";}
else {

$send = mail($to, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.site.com/thanks" );}
else
{print "We encountered an error, please notify

webmaster@YourCompany.com"; }
}
?>

I got the code from http://php.about.com/od/phpapplications/ss/form_mail_3.htm and I altered it.

maximillion
06-29-2011, 06:24 AM
cool, i'll have to test it out.. ty :)

maximillion
06-29-2011, 11:01 AM
didn't work on zymic hosting.. i'll have to try it on another host later today.

Nemesis
06-29-2011, 02:40 PM
didn't work on zymic hosting.. i'll have to try it on another host later today.:eye::eye::eye::eye::eye::eye::eye::eye::eye ::eye:

Hall of Famer
06-29-2011, 02:56 PM
umm Nemisis...

I dont think it makes any differences by switching to a different host, but its just me.

maximillion
06-29-2011, 05:46 PM
i don't think script actually works.. and i'm sure it wasn't even tested before being posted... but at least ruletka tried

Tequila
06-29-2011, 10:29 PM
I found my favorite contact form tutorial though in obscuro (http://inobscuro.com/tutorials/contact-form-34/), there is one other I like at CSS Tricks (http://css-tricks.com/examples/ContactForm/) (great site that one, another that I really recommend is Girls Who Geek (http://girlswhogeek.com) (used to be Tutorialtastic and CodeGrrl)).

maximillion
06-30-2011, 09:04 PM
cool.. ty - but ii just wanted a pre-made script ready for use with just the email and submit

Tequila
06-30-2011, 09:10 PM
The one at CSS Tricks is downloadable, it's just in a neat container. :3 Maybe taking a look at it will make it easier to modify?

ruletka
07-01-2011, 12:51 AM
No, I tested it before I posted it...
Do you have a field that has the name of 'email' (caps matters). Did you add your email in the $to = youremail ? Is there any spaces there or typos? A common reason is because you didnt check the spam mail in your email. It goes to spam because most subdomain hosts arent trusted by email sites.