PHPMailer, return to sender functionality

Posted on 2007-10-05
Last Modified: 2012-08-13

  I would like to have email return to sender functionality if the email is not valid, I have tried this code, but it didn't work, any clue about this?

                  $mail = new PHPMailer();                   
                  $mail->From = $from;
                  $mail->ConfirmReadingTo = $from;
                  $mail->FromName = "";
                  $mail->AddReplyTo($from, "");
                  if ($mail->Send())

Question by:mnasman
    LVL 48

    Accepted Solution

    You can try adding custom headers like:

     $mail->AddCustomHeader('Return-Path: ' . $from);

    LVL 22

    Author Comment

    I tried it, but I didn't got any return email if I sent to unvalid address
    LVL 48

    Assisted Solution

    If you use isMail your local MDA might replace that info when the mail is send through the php-mail-command. Try to use
    $mail->isSMTP() instead os $mail->isMail()
    LVL 17

    Expert Comment

    $mail->Sender = "email@address.exp";
    LVL 22

    Author Comment

    hi nplib, i tried that too after read it in phpmailer doc, but didn't work
    i think the problem as hernst42 said, I need to change it to use SMTP, I tried it but got errors, even i put server and username/password

    could any one give me a complete sample for sending email with smtp and have the return path?, sorry I'm not good in php, this is just a fix i have to do for part from a big application i have
    LVL 17

    Assisted Solution

    if you use $mail->isSMTP();
    then you need to have these lines of code;
    $mail->Host = "IP ADDRESS of SMPT server";
    //If you don't require Authentication on your SMTP server, if its a Public SMTP you shouldn't but
    $mail->SMTPAuth = false;
    //if you require Authentication then add the following instead
    $mail->SMTPAuth = true;
    $mail->Username = "administrator";
    $mail->Password = "password";
    //Obviously use the username and password needed to authenticate on your SMTP server.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now