+ -
当前位置:首页 → 问答吧 → phpmailer发件人问题

phpmailer发件人问题

时间:2010-01-02

来源:互联网

最近在做一个发邮件的东西,遇到了麻烦,各位看一下,帮忙。先做一个简单的例子:
PHP code
<?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]'显示在发件人的位置,不知能否实现?小弟急求,不然工作就丢了.

作者: wdxt206   发布时间: 2010-01-02

变量传给他不就成了。

作者: zxdsu   发布时间: 2010-01-03

这是验证的那个方法,    fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);,这里的这个fputs是怎么工作的啊?不太明白。
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 . '<br />';
      }
      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 . '<br />';
      }
      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 . '<br />';
      }
      return false;
    }

    return true;
  }

作者: wdxt206   发布时间: 2010-01-03