PHPMailer apparently not all messages coming through

For one of my clients I use PHPMailer for handling messages coming from the website.Some time ago he told me that not all messages were coming through. I added my own e-mail address as BCC (which I told the client) and saw a lot of messages coming through. He told me though, that he was called by some customers, telling him that they had sent messages from the website, which he say, he never received.

Is there a way to check if messages were sent that didn’t come through? Or is there any alternative for PHPMailer. Not sure what to do. It’s his word against mine

You could look for some logging options, but IME that would only tell you that they had been delivered to the SMTP server to be sent, not that they had actually been delivered. You can request an acknowledgement, but the receiver can decline to send one.

You really need an example of a client who should have received the email but did not, to narrow down where the problem lies. If you’re sending it and they don’t receive it, in many ways that’s just “one of those things” with email. Any number of intermediates could be spam-trapping, for example.

Isn’t that what is wanted? The OP could then deduce (with the help of the client) which messages had not been delivered, and perhaps find a pattern.

You only can reliable check mail sending if you use SMTP (because that directly connects you with the mail server). Then you can check the mail server logs for failed messages. It might also help to add a bounce address (a recipient that is notified if sending fails).

Since I do not use PHPMailer, you’ll have to check its documentation were to find that.

Whilst not actually fixing the problem I wonder if a solution could be to add an autoreply on the inbox it is being delivered to. Then when a user submits the contact form you could put a message saying ‘you will receive an email shortly confirming your email has reached our inbox. If you don’t hear from us within 24hrs please drop us a line’.

obviously useful to know what is causing the problem if you can find it but this should be a catch all anyway.

Thank you guys so far.

@Dormilich. I am not using SMTP. I need to have a look into that .Which program do you use when I may ask? Or do you use the build in Mail() function?

@Noppy. I don’t use a autoreply but have a success message (for what it si worth :wink: ) telling them what you suggest

What are you using if not?

the problem is with a success message is where it is triggered from. If it’s done straight after the php_mailer send completes then that doesn’t mean that the email was successfully sent it just means that the php_mailer script completed. Hence my reason for suggesting an autoreply on the actual inbox the email is going to as that would definitely only trigger if the email arrived.

This was actually the first time I used PHPMailer. Before I used the build in mail function. This is how i use it right now:

require_once        (APP_PATH.'/lib/PHPMailer/src/PHPMailer.php');				
require_once        (APP_PATH.'/lib/PHPMailer/src/Exception.php');
require_once        (APP_PATH.'/lib/PHPMailer/src/SMTP.php');
$mail 			= 	new PHPMailer(true); 

$mail->setFrom($email, $name);
$mail->addAddress($primary_email, $company_name);
$mail->addAddress($secondary_email, $company_name);

$mail->Subject 	= $subject;
$mail->Body 	= $msg;

It is activated in if($mail->send()) statement

I usually use SwiftMailer, but PHPMailer can also be configured to use SMTP.

You’re including the SMTP library which suggests you are using SMTP. Do you not also have something along the lines of

  $mail->Host = '';
  $mail->SMTPAuth = true;
  $mail->Username = '';
  $mail->Password = 'password';

in your script?

No I don’t have. I remember getting an error message on the SMTP part. I have a question thought. Should the user and password be from that particular e-mail account or can it be any other one on the same server?

The idea with PHPMailer, SwiftMailer and all the others is that you use the mail server to send the emails, so you need to provide the credentials for your mail server, ie a valid email address and password for the mail server rather than for your hosting account.

I’m not sure how the mail is getting sent if you don’t have this.

What I ment is, do you mean the cridentials from this particular e-mail address or can it be from any other e-mail address?

I’m not sure what you mean by this particular email address, but I found (by trial and error) that on my install the from email address needs to be the same as the one I’m using to connect to the mail server. I don’t know if it’s the same for all installations.

You can see just what is going on by enabling verbose debugging:

$mail->SMTPDebug = 2;

What i mean is. In a lot of examples/tutorials they advise you to use gmail.smtp because your website can be blacklisted, for what ever reason. So even if the email address where messages are send to is can I still use the cridentials from a gmail account?, This is confusing me a lot

Ah yes. I can see the confusion. If you’re going to use Gmail’s SMTP then you need to use a Gmail email address and password. It’s not something I have tried, but I suggest you set verbose debugging and suck it and see…

Happy you understand the confusion :slight_smile: When I use his own mail server I can make an extra address on the server and use those cridentials, but it’s very hard to ask the client for his GMail cridentials or can i even use my own cridentials?

You can use any. The only thing that you need to understand is that it has to be correct to the tee. You cannot use an email and randomly decide that it uses tls and not ssl. If the configurations says it’s supposed to use ssl, then you have to use ssl. There is no if’s, and’s, or’s, or but’s when dealing with SMTP. It has to be exact configuration. Also, make sure that the email address you are using actually can send messages using PHP. Some hosters have disabled sending email messages unless the email address is registered under your actual domain and is verified to be a valid email address.

@spaceshiptrooper Ok thanks Gonna give it a try.

@Gandalf. Thanks for all the input!

1 Like