0
<?php
            @require_once"Mail.php";

            $from="from email"; //enter email of sender
            $to="recepient email"; //enter to email
            $subject="subject";

            $body="content";

            $host="ssl://smtp.gmail.com";
            $port="465";
            $username="your gmail account user name";
            $pwd="your gmail account password";

            $headers = array ('From' => $from,
                            'To' => $to,
                            'Subject' => $subject);

            $headers["Content-Type"] = 'text/html; charset=UTF-8';

            $smtp = @Mail::factory('smtp',
                                   array ('host' => $host,
                                             'port' => $port,
                                             'auth' => true,
                                             'username' => $username,
                                             'password' => $pwd));

            //Send Email using pear sned option
            $mail = @$smtp->send($to, $headers, $body);

                //If any errors occurs
            if (@PEAR::isError($mail)) {
               ("<p>" . $mail->getMessage() . "</p>");
            }
            else {
             echo("<p>Message successfully sent!</p>");

            }           

?>

Adding @ reduce some error but still have three errors are coming they are:

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 491

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 265

Strict Standards: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 267

Prashant
  • 71
  • 1
  • 10
  • You cannot have delivery reports that easily, and if you just want that the `mail()` is invoked, you can simply use an insert statement after using `mail()` – Mr. Alien Apr 16 '13 at 18:33
  • You could use delivery receipts, but support is patchy at best. Short answer: no. – leftclickben Apr 16 '13 at 18:33
  • @PK28 See here, http://stackoverflow.com/questions/1078251/delivery-reports-and-read-receipts-in-php-mail But understand that you are relying on the mail server that you are sending to. Not all servers support, and not all server issue delivery receipts. There are no guarantees. – Nilpo Apr 16 '13 at 18:42
  • Yeah, you should precise if you want to be sure that it _has been sent_ (as implied in your headline), or if you want to know if it _has been delivered_. – Gottlieb Notschnabel Apr 16 '13 at 19:09
  • @GottliebNotschnabel deliverd – Prashant Apr 16 '13 at 19:18
  • You won't find a way here if you want regular E-Mails (see answers below). You could just code your own messaging system where you can check delivery. – Gottlieb Notschnabel Apr 16 '13 at 19:19

2 Answers2

1

You could check whether the mail was successfully handed over to the MTA, you can't really detect or check if the mail was successfully delivered to the recipient. That is a different case.

To check whether the mail was sent :

if (mail('abc@gmail.com',$subject,$body,'From: me@example.org'))
    return true;
else
    return false;

So your function will be :

 function email($to,$subject,$body)
 {
     if (mail('abc@gmail.com',$subject,$body,'From: me@example.org'))
        return true;
    else
        return false;
 }

Since mail function always return boolean value, tt can be simplified as :

function email($to,$subject,$body)
{
   return  mail('abc@gmail.com',$subject,$body,'From: me@example.org');

}

Alternately if you have set reply-to in your mail header, then you can check for any bounced mail which will let you say with certainty that a message hasn't been delivered.

Sabari
  • 6,205
  • 1
  • 27
  • 36
  • I agree. Since the mail function always returns a boolean value, you could clean this a bit by simply returning that line without the conditional. – Nilpo Apr 16 '13 at 18:34
  • is there any way to send the email on some local mail server and if so then how to establish local mail server – Prashant Apr 16 '13 at 18:38
  • @PK28 It depends how your server is configured. If this is running on Apache for example, PHP's mail function will use the local server's sendmail program by default. This can all be changed through Apache/PHP settings though. – Nilpo Apr 16 '13 at 18:39
  • @PK28 you can use gmail smtp for sending mail from local machine. You can set up a Fake Sendmail (http://glob.com.au/sendmail/) in your local machine and apply Gmail SMTP server settings – Sabari Apr 16 '13 at 18:41
  • is roundcube will be helpfull for checking such thing – Prashant Apr 16 '13 at 18:42
  • @PK28 No, Roundcube is just webmail interface for the email applications. (Typically postfix for SMTP.) – Nilpo Apr 16 '13 at 18:45
  • @Sabari I am working on windows 8 and windows 8 doesnt support fake sendmail – Prashant Apr 16 '13 at 18:47
1

You either have to install a mailserver for xampp, e.g. Mercury. Or you have to enter your (external) SMTP credentials into your php.ini.

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116