Click here to Skip to main content
15,746,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this mailer is send mail but ,
but not showing mail delivery error after send mail ,
I want to get delivery error if mail is not send successfully.

What I have tried:

require_once(APPPATH . '../third_party/PHPMailer/src/PHPMailer.php');
			require_once(APPPATH . '../third_party/PHPMailer/src/SMTP.php');
			require_once(APPPATH . '../third_party/PHPMailer/src/Exception.php');

			// Load Composer's autoloader
			require 'application/helpers/vendor/autoload.php';
			// Instantiation and passing `true` enables exceptions
			$mail = new PHPMailer(true);

			try {
				//Server settings
				$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
				$mail->isSMTP();                                            // Send using SMTP
				$mail->Host       = '';                   // Set the SMTP server to send through
				$mail->SMTPAuth   =  true;                                   // Enable SMTP authentication
				$mail->Username   = '';                     // SMTP username
				$mail->Password   = 'xxxx';                               // SMTP password
				$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
				$mail->Port       = 587;    
				// $mail->SMTPDebug  = 1; 
				$mail->setFrom('', 'Mailer');
				$mail->addAddress($data['mail'], 'Deepak Agarwal');     // Add a recipient
				// Attachments
				if($data['path'] != "" && $data['file'] != "")
				// $mail->addAttachment('2.png');         // Add attachments
				// $mail->addAttachment('3.png');         // Add attachments
				//$mail->addAttachment('1.png', 'Certificate Logo.png');    // Optional name

				// Content
				$mail->isHTML(true);                                  // Set email format to HTML
				$mail->Subject = $data['subject'];
				$mail->Body    = $data['message'];
				$mail->AltBody = $data['message'];
					// $this->CI->session->set_flashdata('msg', 'Message has not  sent successfully.');
					echo $mail->ErrorInfo;
					echo "Not send";
				}else if(!$mail->ValidateAddress($data['mail'])){
					$this->CI->session->set_flashdata('errmail','Mail Not Send..!');
					$this->CI->session->set_flashdata('msg', 'Message has been sent successfully.');
			catch (phpmailerException  $e) {
				$this->CI->session->set_flashdata('errmail', $e->errorMessage()); //Pretty error messages from PHPMailer
				echo $e->errorMessage();
			catch (Exception $e) {
				$this->CI->session->set_flashdata('errmail', $e->getMessage()); //Boring error messages from anything else!
				echo $e->getMessage();
Updated 23-Dec-19 9:24am

The response you get is from the (your) email server; and there is no guarantee that your email server will know the status of a recipients mailbox on a different server.

Email also is not an instant point-to-point system; resilience is built in to retry connections at specified intervals for a set amount of time. It is not uncommon to find SMTP servers set up to keep trying to send a message for several days. Obviously... you aren't going to wait that long to receive an "OK" message from your application.

You may want to do some Googling on how email actually works, particularly SMTP Lifecycle and SMTP response codes.
Share this answer
What do you mean by "delivery error"? If the email address appears to be valid, then it will get sent from your server. Only when the remote address finds that the name does not exist will it respond to you with an undeliverable message. But that can be minutes, hours or even days later.
Share this answer
Member 14697878 23-Dec-19 8:28am    
I want to get mail delivery notification if mail format is correct like ( , but this mail is not correct. So I want to (invalid mail) notification..

I this code not showing any error if mail is incorrect.
Richard MacCutchan 23-Dec-19 8:55am    
You cannot get it, since the address is technically correct. Only when it gets to the gmail server will it be rejected, when gmail cannot find a mail entry for the name "abc". And then all it can do is send an email message to the address in the sender field of the original message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900