0
votes
<?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

2
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
You could use delivery receipts, but support is patchy at best. Short answer: no. - leftclickben
@PK28 See here, stackoverflow.com/questions/1078251/… 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
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
@GottliebNotschnabel deliverd - Prashant

2 Answers

1
votes

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('[email protected]',$subject,$body,'From: [email protected]'))
    return true;
else
    return false;

So your function will be :

 function email($to,$subject,$body)
 {
     if (mail('[email protected]',$subject,$body,'From: [email protected]'))
        return true;
    else
        return false;
 }

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

function email($to,$subject,$body)
{
   return  mail('[email protected]',$subject,$body,'From: [email protected]');

}

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.

1
votes

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.