最近在做一个发邮件的东西,遇到了麻烦,各位看一下,帮忙。先做一个简单的例子:<?php 
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->CharSet = 'utf-8';
$mail->Encoding = 'base64';
$mail->From = '[email protected]';
$mail->FromName ='SRV Chinese School';
$mail->Host ='ssl://smtp.gmail.com';
$mail->Port = 465; 
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "***************";
$mail->AddAddress("[email protected]");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "[测试]this is a test email from phpmailer";
$mail->Body = "Do you receive it?你收到了吗?";
if(!$mail->Send())
{
echo "通知信件寄出失敗";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "通知信件已寄出";
?>收取情况如下:
主 题: [测试]this is a test email from phpmailer                 
时 间: 2010年1月1日(星期五) 11:32 
发件人: "SRV Chinese School" <[email protected]>
收件人: [email protected] 
抄送人: (无) 
问题是:发件人显示的是[email protected]  ,但是我想让$mail->From = '[email protected]';中的这个'[email protected]'显示在发件人的位置,不知能否实现?小弟急求,不然工作就丢了.

解决方案 »

  1.   

    整个类的代码太多不方便全部贴出,这就是phpmailer里面的smtp.class.php中的一个方法。这个方法就是用来验证用户的,其中$username='[email protected]',也就是现在的发件人。
      public function Authenticate($username, $password) {
        // Start authentication
        fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);    $rply = $this->get_lines();
        $code = substr($rply,0,3);    if($code != 334) {
          $this->error =
            array("error" => "AUTH not accepted from server",
                  "smtp_code" => $code,
                  "smtp_msg" => substr($rply,4));
          if($this->do_debug >= 1) {
            echo "SMTP -> ERROR: " . $this->error["error"] .
                     ": " . $rply . $this->CRLF;
          }
          return false;
        }    // Send encoded username
        fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);    $rply = $this->get_lines();
        $code = substr($rply,0,3);    if($code != 334) {
          $this->error =
            array("error" => "Username not accepted from server",
                  "smtp_code" => $code,
                  "smtp_msg" => substr($rply,4));
          if($this->do_debug >= 1) {
            echo "SMTP -> ERROR: " . $this->error["error"] .
                     ": " . $rply . $this->CRLF;
          }
          return false;
        }    // Send encoded password
        fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);    $rply = $this->get_lines();
        $code = substr($rply,0,3);    if($code != 235) {
          $this->error =
            array("error" => "Password not accepted from server",
                  "smtp_code" => $code,
                  "smtp_msg" => substr($rply,4));
          if($this->do_debug >= 1) {
            echo "SMTP -> ERROR: " . $this->error["error"] .
                     ": " . $rply . $this->CRLF;
          }
          return false;
        }    return true;
      }