想用PHP写个表单发邮件到邮箱里。
表单里面有姓名,性别等。。按提交后就直接能发到邮箱了。哪位好心人能提供下具体代码呢?网上找了很多都不行的
~~
编译通过后,我会追加分数滴~~

解决方案 »

  1.   

    刚做了个这样的单子! 
    项目主要是一个 公司要发送贺卡到用户邮箱  表单上面有对方邮箱地址 祝福话语等等 提交就直接发送到对方的邮箱里面了 用的是phpmailer类 如果  SMTP 用的是GMAIL 提供的   
    代码如下<?php
    header("Content-type:text/html;charset=utf8");
    require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录
    include("class.smtp.php");
    @$action = $_REQUEST['action'];
    @$reciver_address = $_REQUEST['reciver_address'];
    @$reciver_name = $_REQUEST['reciver_name'];
    @$reciver_content = $_REQUEST['reciver_content'];
    if($action == 'send'){
    $mail = new PHPMailer(); //建立邮件发送类

    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port
    $mail->CharSet = "UTF-8";
    //$address = $_POST['address'];
    $mail->IsSMTP(); // 使用SMTP方式发送
        $mail->Subject = $reciver_name."祝贺您新春愉快"; //邮件标题
    $mail->Username = "[email protected]"; // 邮局用户名(请填写完整的email地址)
    $mail->Password = "xxxxx"; // 邮局密码
    $mail->FromEmail = "[email protected]"; //邮件发送者email地址
    //$mail->From = "[email protected]";
    $mail->FromName = "xxxx";
    $mail->AddAddress("$reciver_address", "");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
    $mail->AddReplyTo("[email protected]", "xxxx");
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
    $mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
        $html_content = file_get_contents('demo.html');
    //$html_content = iconv("gb2312", "utf-8",html_content); 
    $html_content = str_replace('sender_name', $reciver_name, $html_content);
    $html_content = str_replace('sender_content', $reciver_content, $html_content);
    //$html_content = iconv("gb2312", "utf-8",html_content); 
    //create demo.html BEGIN staticdemo

    $filename = 'email'.rand(1,10).date("YmdHis",time());
    $filename = 'static/'.$filename.'.html';
    $static_html = file_get_contents('static.html');
    $static_html = str_replace('sender_name', $reciver_name, $static_html);
    $static_html = str_replace('sender_content', $reciver_content, $static_html);
    if(!file_exists($filename)){
    $fp=fopen("$filename","w+");//fopen()的其它开关请参看相关函数
    $str="$static_html";
    fputs($fp,$str);
    fclose($fp);
    }
    $html_content = str_replace('staticdemohtml', $filename, $html_content);
    //create demo.html END
    //$html_content = $html_content.'请勿回复!!';
    //$html_content = eregi_replace("[\]",'',$html_content);
    //$$html_content = "=?UTF-8?B?".base64_encode($html_content)."?=";
    $mail->Body = $html_content;
    //$mail->Body = iconv("GB2312","UTF-8", "$html_content"); //邮件内容
    //$mail->Body = "$html_content"; //邮件内容
    //$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
    if(!$mail->Send())
    {
    echo "Sorry! Sending Failure!!!";
    echo "<a href='http://xxxxxx/bocigroup/fish.html'>BACK</a>";
    }else{
    echo "Congratulations! Sending Success!!!";
    header("Location:http://xxxxx/bocigroup/back2.html");
    }
    }
    ?>
      

  2.   

    这里只提供一个思路!  具体代码 还是要你自己依照你自己情况写! 我上面中间有一段代码 是用来生成静态贺卡的 (贺卡里面有FLASH) 你可以去掉  
      

  3.   

    我每次运行 require("class.phpmailer.php");  localhost就报错:Parse error: parse error in C:\wamp\www\testmail1.php on line 12
    我的代码:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <?php  
    //header('Content-Type: text/html; charset=utf-8');  require_once(PEAR_PATH."class.phpmailer.php");  
    error_reporting(E_ERROR);  
       
     function smtp_mail ( $sendto_email, $subject, $body ,$att=array()) {   //require = ("class.phpmailer.php"); //下载的文件必须放在该文件所在目录   $mail = new phpmailer(true); //建立邮件发送类   $address->$_POST['address'];   
    $mail->IsSMTP(); // 使用SMTP方式发送  
     $mail->Host = "mail.qq.com"; // 您的企业邮局域名 
      $mail->SMTPAuth = true; // 启用SMTP验证功能  
     $mail->Username = "[email protected]"; // 邮局用户名(请填写完整的email地址) 
     // $mail->Password = "******"; // 邮局密码  
     //$mail->From = "[email protected]"; //邮件发送者email地址  
     $mail->FromName = "开心果";   
    $mail->[email protected]("$address", "");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")   //$mail->AddReplyTo("", "");  
     //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件  
     //$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式  
     $mail->Subject = "PHPMailer测试邮件"; //邮件标题  
     $mail->Body = "Hello,这是测试邮件"; //邮件内容  
     $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
       if(!$mail->Send())  
      {   
     echo "邮件发送失败. <p>";   
     echo "错误原因: " . $mail->ErrorInfo;  
      exit;  
      }   
     echo "邮件发送成功";   ?>
    }
    </body>
    </html>
      

  4.   

    class.phpmailer.php 的代码  是网上下载下来的源码,这个又是什么问题呢??
      

  5.   

    把你的代码 打包 发给我  !  [email protected]