dongpai6552 2013-07-11 11:19
浏览 109

用附件发送带有php的电子邮件

i have use this code in php mail send with attachment. I am using the Apache http server with wamp.

            <?php $to = 'santosh_091020@rediffmail.com';

// Declaring the necessary variables for mail sending :

                $subject  = 'Testing sendmail.exe';
                $name = $_REQUEST['name'] ;
                $email = $_REQUEST['email'] ;
                $mob = $_REQUEST['mob'] ;
               $msg = $_REQUEST['msg'] ; 
               $message  = ' santosh enquire 

Name: '.$name.' 
 Email:'. $email.' 
 Mobile:'.     $mob.' 
 Message: '.$msg.' 
 ';

// Declaration of the attributes for attachment.

               $upload_name=$_FILES["upload"]["name"];
               $upload_type=$_FILES["upload"]["type"];
               $upload_size=$_FILES["upload"]["size"];
               $upload_temp=$_FILES["upload"]["tmp_name"];
               $fp = fopen($upload_temp, "rb");
               $file = fread($fp, $upload_size);
                fclose($fp);
              $file = chunk_split(base64_encode($file));
              $num = md5(time());

// Defining the contents of the header.

               $headers = "From: ".$email. "
" . "CC: santosh@creativecrows.com" ;

               $headers  .= "MIME-Version: 1.0
";
               $headers  .= "Content-Type: multipart/mixed; ";
               $headers  .= "boundary=".$num."
";
               $headers  .= "--$num
";

              //$headers .= "Message-ID: <".gettimeofday()."  TheSystem@".$_SERVER['SERVER_NAME'].">
";
               $headers .= "X-Mailer: PHP v".phpversion()."
";

               $headers .= "Content-Type: text/html; charset=iso-8859-1
";
               $headers .= "Content-Transfer-Encoding: 8bit
";
               $headers .= "".$message."
";
               $headers .= "--".$num."
";

               $headers  .= "Content-Type:".$upload_type." ";
               $headers  .= "name=\"".$upload_name."\"r
";
               $headers  .= "Content-Transfer-Encoding: base64
";
               $headers  .= "Content-Disposition: attachment; ";
               $headers  .= "filename=\"".$upload_name."\"

";
               $headers  .= "".$file."
";
               $headers  .= "--".$num."--"; 
              //$data = chunk_split(base64_encode($data));

// sending the mail.

               if(mail($to, $subject, $message, $headers))
                {
               echo "Email sent";
               send();

                } 
               else
                {
               echo "Email sending failed";
                }
    //send mail in client   
               function send()
                {
               $email = $_REQUEST['email'] ;
               $name = $_REQUEST['name'] ;
               $to= trim($email);   
               $subject  = 'thanx';
               $message = '<html><head><title>HTML email</title></head>
              <body style="background-color:#000099;"><p style="color:#000099;">This email contains  HTML Tags!</p><table><tr><th>Firstname</th><th>Lastname</th></tr><tr><td>John</td><td>Doe</td></tr></table></body></html>';$headers1 = 'MIME-Version: 1.0' . "
";
               $headers1.= 'Content-type: text/html; charset=iso-8859-1' . "
";
               $headers1.= "From: ".$email;

               if(mail($to, $subject, $message,$headers1))
                {
               echo "Email sent";
                }
               else
                {
               echo "Email sending failed";
               echo $to;
               echo $subject;
               echo $message;
                }
            }

            ?>

but i got the following error;

Delivery to the following recipient failed permanently:

                 1.0@localhost

Technical details of permanent failure:
DNS Error: Domain name not found.

please help me. Thnx in advance.

  • 写回答

2条回答 默认 最新

  • doujun1495 2013-07-11 11:24
    关注

    Check this URL, seems your header info is not absolute http://webcheatsheet.com/php/send_email_text_html_attachment.php

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试