File attachment with PHPMailer

When you call move_uploaded_file($file_tmp,”uploads/”.$file_name); This creates a file in the uploads/ directory with the name of the file as it was named on the uploader’s computer. Then you used sample code to add the attachment to phpMailer so you’re basically attempting to attach non-existent files. These two lines: $mail->addAttachment(‘uploads/file.tar.gz’); // I took this from the … 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 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

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 – SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

PHP 5.6 introduces SSL certificate verification, so if your config is broken, it will fail with this error. You should fix your SSL, but you can revert to the old behaviour by setting the SMTPOptions property to not verify certificates: $mail->SMTPOptions = array( ‘ssl’ => array( ‘verify_peer’ => false, ‘verify_peer_name’ => false, ‘allow_self_signed’ => true … Read more

Configure WAMP server to send email

Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. I’m sure someone more experienced may be able to help, or they may perhaps agree with me. If you just want to test, here is a great tool for testing mail locally, that requires almost no … Read more

PHPMailer AddAddress()

You need to call the AddAddress function once for each E-Mail address you want to send to. There are only two arguments for this function: recipient_email_address and recipient_name. The recipient name is optional and will not be used if not present. $mailer->AddAddress(‘recipient1@example.com’, ‘First Name’); $mailer->AddAddress(‘recipient2@example.com’, ‘Second Name’); $mailer->AddAddress(‘recipient3@example.com’, ‘Third Name’); You could use an array … Read more