Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP电子邮件表单帮助-@符号不工作_Php_Html_Forms_Email_Post - Fatal编程技术网

PHP电子邮件表单帮助-@符号不工作

PHP电子邮件表单帮助-@符号不工作,php,html,forms,email,post,Php,Html,Forms,Email,Post,如果@符号在电子邮件行中提交的表格中,则不会发送电子邮件。Ie:如果你在电子邮件表单中键入bob,它会工作,但是bob@gmail.com不。我怎样才能使它正常工作?如果@符号在行中,则根本不会发送电子邮件 <?php $to = "MYEMAIL@gmail.com"; $name = $_POST['name']; $email = $_POST['email']; $add = $_POST['add']; $city = $_POST['city']; $state = $_POS

如果@符号在电子邮件行中提交的表格中,则不会发送电子邮件。Ie:如果你在电子邮件表单中键入bob,它会工作,但是bob@gmail.com不。我怎样才能使它正常工作?如果@符号在行中,则根本不会发送电子邮件

<?php
$to = "MYEMAIL@gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$add = $_POST['add'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$subject= "Request For Quote from Latva";
$message = "
Full Name - $name
Email - $email
Address - $add
City - $city
State - $state
Zip - $zip
Phone - $phone
Message - $comments
";
  $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
         $headers = "From: ".$name." <".$email.">\r\n" .
         "MIME-Version: 1.0\r\n" .
            "Content-Type: multipart/mixed;\r\n" .
            " boundary=\"{$mime_boundary}\"";
         $message = "This is a multi-part message in MIME format.\n\n" .
            "--{$mime_boundary}\n" .
            "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
            "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";
         foreach($_FILES as $userfile)
         {
            $tmp_name = $userfile['tmp_name'];
            $type = $userfile['type'];
            $name = $userfile['name'];
            $size = $userfile['size'];
            if (file_exists($tmp_name))
            {
               if(is_uploaded_file($tmp_name))
               {
                  $file = fopen($tmp_name,'rb');
                  $data = fread($file,filesize($tmp_name));
                  fclose($file);
                  $data = chunk_split(base64_encode($data));
               }
               $message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$type};\n" .
                  " name=\"{$name}\"\n" .
                  "Content-Disposition: attachment;\n" .
                  " filename=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
               $data . "\n\n";
            }
         }
         $message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
   echo "Mail sent successfully.";
else
   echo "Error in mail";
?>


您必须注意正确转义放入标题中的所有字符串。这些只能访问7bit字符。因此,您需要通过编码转换所有其他内容。类似的情况也适用于“特殊角色”,如换行符等。想象一下,如果您在
$name
变量中输入这些内容,会发生什么……停止手动构建电子邮件标题。您的头容易被注入,这将允许攻击者从您的服务器发送垃圾邮件。有很多陷阱。使用一个合适的类,比如@arkascha的意思是:使用邮件库