Jump to content

Super simple code doesnt work


andrewburgess

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

the first one checks if the file one intended to attach exists, if it doesnt it emptys $file
then 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...
Link to comment
Share on other sites

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]<?php

if (!file_exists($file))
{
    $file = '';
}
else
{
    // attach
}

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.