andrewburgess Posted November 22, 2006 Share Posted November 22, 2006 Hi all,I have a input text box in my flash site for people to enter their email address. This address is sent to me by email message and i can save it into my contact list. The flash site creates the variable "email" and the php is the following but it doesnt work somehow :'(<?php$sendTo = "myemail@mywebsite.com";$subject = "Please add me to your mailing list";$message = $_POST["email"];mail($sendTo, $subject, $message);?>Any suggestions?AB Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 22, 2006 Share Posted November 22, 2006 are you sure your getting a value in $_POST['email']. and i would replace the " with ' to, because ' is proper coding. anyways. check to make sure your gettting some data from the variable by echoing it then exiting.[code=php:0]echo $_POST['email'];exit;[/code]put that at the top of the script that receives the data. Quote Link to comment Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 this might look a little complicated, and its taken me a while to perfect... but its pretty simple... it includes all the headers needed to send emails to almost everywhere :-)[code]<?function get_filename($filepath,$extension=4){ $length = strlen($filepath) - $extension; return substr($filepath,0,$length);}function email($to, $subject="N/A", $text, $from="", $file=""){ if(is_array($to)) $to = implode(", ",$to); if(empty($to)) return FALSE; $subject=strip_tags($subject); $text = wordwrap($text, 77, "<br />\n"); if((!empty($file))&&(!file_exists($file))) $file=""; if(!empty($file)){ switch(get_filetype($file,3)){ case ".rm": $type="audio/x-realaudio"; break; case ".qt": $type="video/quicktime"; break; } switch(get_filetype($file)){ case ".avi": $type="video/avi"; break; case ".doc": $type="application/msword"; break; case ".gif": $type="image/gif"; break; case ".jpg": $type="image/jpeg"; break; case ".mov": $type="video/mov"; break; case ".mpg": $type="video/mpeg"; break; case ".pdf": $type="application/pdf"; break; case ".png": $type="image/png"; break; case ".ram": $type="audio/x-pn-realaudio"; break; case ".tar": $type="application/x-tar"; break; case ".wav": $type="audio/wav"; break; case ".zip": $type="application/x-zip-compressed"; break; } switch(get_filetype($file,5)){ case ".html": $type="text/html"; break; case ".mpeg": $type="video/mpeg"; break; } if(!isset($type)) $type="text/plain"; $content = fread(fopen($file,"r"),filesize($file)); $content = chunk_split(base64_encode($content)); $name = basename($file); } $uid = strtoupper(md5(uniqid(time()))); $header = "From: $from\nReply-To: $from\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: multipart/mixed; boundary=$uid\n"; $header .= "--$uid\n"; $header .= "Content-Type: text/html\n"; $header .= "Content-Transfer-Encoding: 8bit\n\n"; $header .= "$text\n"; $header .= "--$uid\n"; if(!empty($file)){ $header .= "Content-Type: $type; name=\"$name\"\n"; $header .= "Content-Transfer-Encoding: base64\n"; $header .= "Content-Disposition: attachment; filename=\"$name\"\n\n"; $header .= "$content\n"; $header .= "--$uid--"; } if(mail($to, $subject, $text, $header)) return TRUE; else return FALSE;}?>[/code] Quote Link to comment Share on other sites More sharing options...
Jenk Posted November 22, 2006 Share Posted November 22, 2006 taith.. that could do with some cleaning up :\ [code]<?phpif ((!empty($file)) && (!file_exists($file))) $file="";if (!empty($file)) // unecessary challenge..?>[/code]for a start, and it's also incredibly vulnerable to header injection. Quote Link to comment Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 nono... those are both necessary[code]<?if ((!empty($file)) && (!file_exists($file))) $file="";?>[/code]that takes a look, if someone fills in the $file, but the file doesnt exist, it removes it[code]<?if (!empty($file)) // completly necessary challenge..?>[/code]then it goes on to see if the file is still being attached Quote Link to comment Share on other sites More sharing options...
Jenk Posted November 22, 2006 Share Posted November 22, 2006 what I mean is, it should be:[code]<?phpif ((!empty($file)) && (!file_exists($file)){ $file = "";}else{ // the rest?>[/code] Quote Link to comment Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 only big difference that would do the same thing... would be changing the [code]if (!empty($file))[/code]to[code]elseif (!empty($file))[/code] Quote Link to comment Share on other sites More sharing options...
Jenk Posted November 22, 2006 Share Posted November 22, 2006 but why check !empty() twice? There is no need.. Quote Link to comment Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 the first one checks if the file one intended to attach exists, if it doesnt it emptys $filethen it goes through again and see's if $file is empty, if not, it goes ahead and attaches the file.if we did it once, it'd empty the file, and still attach it... Quote Link to comment Share on other sites More sharing options...
Jenk Posted November 22, 2006 Share Posted November 22, 2006 no, becuase if you structured it once, as I posted above, it would either empty it, if the filename does not exist, or attach it..Infact you could drop empty() all together with:[code]<?phpif (!file_exists($file)){ $file = '';}else{ // attach}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.