你知道是否可以使用 PHP 中的 Pear Mail 函数设置 DSN 通信?
说明:如果在 telnet 会话中编写此代码:
telnet smtp.example.com 25
[...]
mail from: me@example.com
250 2.1.0 Ok
rcpt to: you@fakemail.com NOTIFY=SUCCESS,FAILURE,DELAY ORCPT=rfc822;you@fakemail.com
250 2.1.5 Ok
[]
当我的 smpt 服务器发送电子邮件时,我收到了来自接收方 smtp 服务器(已中继、失败等)的带有状态代码的通知邮件。现在我想用 Pear Mail 做同样的事情,但我找不到我把这个选项放在哪里。
这是我的代码:
$messageTEXT= "..." // text_message
$messageHTML="..." // html message
$headers=array();
$headers['From'] = "me@example.com";
$headers['To'] = "you@fakemail.com";
$headers['Subject'] = "Test mail";
$headers['X-Mailer']="My PHP mailer";
$headers['X-Priority']=3;
$headers['Errors-To'] = "me@example.com";
$headers['Return-Path'] = "me@example.com";
$headers['Disposition-Notification-To'] = "me@example.com";
$message = new Mail_mime();
$message->setTXTBody($messageTEXT);
$message->setHTMLBody($messageHTML);
$mimeparams=array();
$mimeparams['charset']= "UTF-8";
$mimeparams['text_encoding']="8bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$body = $message->get($mimeparams);
$headers = $message->headers($headers);
$smtp = Mail::factory(
'smtp',
array(
'host' => "smtp.example.com",
'port' => "25",
'auth' => true,
'username' => "myuser",
'password' => "mypass")
);
$mail=$smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
print ("Error");
return false;
}