dongsi2317 2014-09-25 10:50
浏览 50

PHP表单电子邮件+写入CSV

I have this form where I wan't people to sign up for receiving free stuff campaign. The form works fine and its send the details to the requested eMail. Now this form should also write the details to a csv file that we can handle the data more easily.

I use this form: $value) { ${"".$key} = $value; }

if (!isset($email)) {
        header( "Location: $formurl" );
    exit;
}

if ($_POST['services']) {
  foreach($_POST['services'] as $value) {
    $check_msg .= "- $value
";
 }
}

function is_email($email) {
    return ereg("^[^@ ]+@[^@]+\.[^@ ]+$", $email);
}

function validate_email($email) {

   // Create the syntactical validation regular expression
   $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";

   // Presume that the email is invalid
   $valid = 0;

   // Validate the syntax
   if (eregi($regexp, $email))
   {
      list($username,$domaintld) = split("@",$email);
      // Validate the domain
      if (getmxrr($domaintld,$mxrecords))
         $valid = 1;
   } else {
      $valid = 0;
   }

   return $valid;

}


$formurl = "/sticker/index.php" ;
$errorurl1 = "/sticker/error.php" ;
$errorurl2 = "/sticker/error.php" ;
$thankyouurl = "/sticker/success.php#start" ;

$http_referrer = getenv( "HTTP_REFERER" );


// get POST && GET vars to run with 'register_globals off'
//foreach($_GET AS $key => $value) {
//    ${"".$key} = $value;
//}

$messageproper =
"============================================================
" .
"Sticker Request $firstname $lastname
" .
"============================================================

" .

"KUNDENDATEN

" .

"Vorname: $firstname
" .
"Nachname: $lastname
" .
"Firma: $company
" .
"Strasse: $street
" .
"Strasse2: $street2
" .
"PLZ: $zip
" .
"City: $city
" .
"Land: $country

" .

"Telefon: $phone
" .
"eMail: $email
" .
"Facebook Name: $fbname

" .

"--------------------------------------

" .

"Bemerkung: $comment

" .

"============================================================

" ;

$myFile = "/sticker/sticker.txt";
$fh = fopen($myFile, 'a');
$stringData = "
";
$x=0;
foreach($_POST AS $key => $value) {
    $x!=0?$stringData=",".$stringData:'';
    $stringData='"'.$firstname.'";"'.$lastname.'";"'.$company.'";"'.$street.'";"'.$street2.'";"'.$zip.'";"'.$city.'";"'.$country.'";"'.$phone.'";"'.$email.'";"'.$fbname.'";"'.$comment.'"'."
";
    $x++;
}
fwrite($fh, $stringData);
fclose($fh);


$mailto = 'email@domain.com' ;
$subject = "Free Sticker Campaign: $company - $firstname $lastname";
mail($mailto, $subject, $messageproper, "From: \"$firstname $lastname\" <$email>
Reply-To: \"$lastname\" <$email>
X-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit;

?>

As I said nothing gets written to the CSV File I declared in $myFile. Would be great if someone could let me know what to do. Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 wegame打不开英雄联盟
    • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多