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]'显示在发件人的位置,不知能否实现?小弟急求,不然工作就丢了.
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;
}
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28