The best way to handle errors is to use a try/catch block to catch the exception, as shown in the previous examples. If something goes wrong while trying to send the message, the PHPMailer object throws and exception (if TRUE is passed to the constructor) and saves the error information inside the $ErrorInfo attribute. In the following example we set the verify_peer and verify_peer_name parameters to FALSE and the allow_self_signed parameter to TRUE in order to disable some security checks: In these cases, you can use the SMTPOptions attribute to tell PHPMailer (and the PHP SSL subsystem) to ignore this issue. This is a quite common scenario in work environments. While you won’t need to use it most of the time, in some cases it can be really useful.įor example, if you have your own SMTP server which uses a self-signed certificate, the SMTP connection will probably fail for the lack of a valid certification authority signature. You can use the SMTPOptions attribute to set advanced SSL context options. If you are using SMTP encryption, PHPMailer passes this array to the underlying PHP stream_context_create() function. Of course, you need to use the correct connection parameters, including the server encryption capabilities and the TCP port it listens to.Ī more advanced SMTP related attribute is the SMTPOptions array. * PHP exception (note the backslash to select the global namespace Exception class). $mail->Body = 'There is a great disturbance in the Force.' Let’s see both installation options, starting with the one with 'Darth Vader') However, the second option may be useful if you don’t want to install Composer for some reason, for example if you are using PHPMailer on a testing environment. This is especially useful if you need to install other libraries as well, like the one needed for XOAUTH2 Google authentication (I will tell you how to use XOAUTH2 with Google later in this post). The first option is the recommended one, because Composer takes care of all the download, update and dependency check steps.
0 Comments
Leave a Reply. |