Could not connect to SMTP host

OS CentOS 6.3 Couldn’t send emails after some reserch turned out that SELinux is blocking the communication SELinux is activated and configured by default. As such SELinux does not allow Apache (httpd,phpmailer) to use the sendmail function and make any sort of network connection. Using the getsebool command we can check if httpd demon is … Read more

Setting up PHPMailer with Office365 SMTP

@nitin’s code was not working for me, as it was missing ‘tls’ in the SMTPSecure param. Here is a working version. I’ve also added two commented out lines, which you can use in case something is not working. <?php require ‘vendor/phpmailer/phpmailer/PHPMailerAutoload.php’; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host=”smtp.office365.com”; $mail->Port = 587; $mail->SMTPSecure=”tls”; $mail->SMTPAuth = true; $mail->Username=”[email protected]”; … Read more

PHP mailer multiple address [duplicate]

You need to call the AddAddress method once for every recipient. Like so: $mail->AddAddress(‘[email protected]’, ‘Person One’); $mail->AddAddress(‘[email protected]’, ‘Person Two’); // .. Better yet, add them as Carbon Copy recipients. $mail->AddCC(‘[email protected]’, ‘Person One’); $mail->AddCC(‘[email protected]’, ‘Person Two’); // .. To make things easy, you should loop through an array to do this. $recipients = array( ‘[email protected]’ => … Read more

PHPMailer character encoding issues

If you are 100% sure $message contain ISO-8859-1 you can use utf8_encode as David says. Otherwise use mb_detect_encoding and mb_convert_encoding on $message. Also take note that $mail -> charSet = “UTF-8”; Should be replaced by: $mail->CharSet = “UTF-8”; And placed after the instantiation of the class (after the new). The properties are case sensitive! See … Read more

“Password not accepted from server: 535 Incorrect authentication data” when sending with GMail and phpMailer

The solution was to enable outgoing SMTP from the server settings. On servers running cPanel’s WHM, this is located under WHM’s “Tweak Settings” section. The option is to enable/disable – choose disable. Caveat: Making this change will redirect outgoing SMTP connections allow accounts to make direct connections which may increase your odds of getting your … Read more

PHPMailer generates PHP Warning: stream_socket_enable_crypto(): Peer certificate did not match expected

I had the same problem and I found the answer in the PHPMailer documentation. PHP 5.6 certificate verification failure In a change from earlier versions, PHP 5.6 verifies certificates on SSL connections. If the SSL config of the server you are connecting to is not correct, you will get an error like this: Warning: stream_socket_enable_crypto(): … Read more

phpmailer and gmail SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed

You might want to start by isolating this problem to determine whether it’s truly a network problem; or whether it’s specific to PHP mailer or your code. On your server, from a command prompt, try using telnet to connect to smtp.gmail.com on port 587, like so: telnet smtp.gmail.com 587 You should see a response from … Read more