2

Do you know if it is posible to set a DSN communication using the Pear Mail function in PHP?

Explain: If a write this code in a telnet session:

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
[]

i received a notification mail with a status code from the receiver smtp server (relayed, failed, etc.) when my smpt server sends the email. Now i want to do the same using Pear Mail, but I can't find where i have tu put this option.

This is my code:

$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;
}

http://pear.php.net/manual/en/package.mail.mail.php

ivan_vaz
  • 110
  • 2
  • 12
  • `$headers['X-Mailer']="X-Mailer: My PHP mailer";` should read `$headers['X-Mailer']="My PHP mailer";` - although that isn't the problem (or even really *a* problem) – DaveRandom Nov 30 '11 at 16:10

1 Answers1

0

You will have to hack PEAR::Mail and Net::SMTP a bit to get this to work.

The standard Mail_smtp::send() method calls into Mail_RFC822::parseAddressList() which will reject the extra data. Commenting out those lines (around line 274) should get you started.

Then you'll need to hack Net_SMTP::rcptTo() to pass the raw data rather than wrapping it in angle brackets.

Make sure your data is being sanitized somewhere else if you're going to circumvent those methods.

Terence Johnson
  • 1,637
  • 1
  • 16
  • 21