1

I'm trying to send email with PHPMailer. Here is my code:

<?php
require_once('PHPMailer/PHPMailerAutoload.php');
class Mail {
    public static function sendMail($subject, $body, $address) {
            $mail = new PHPMailer();
            $mail->isSMTP();
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = 'ssl';
            $mail->Host = 'ssl://sub5.mail.dreamhost.com';
            $mail->Port = '587';
            $mail->isHTML();
            $mail->Username = 'user@name.com';
            $mail->Password = 'password';
            $mail->SetFrom('user@name.com');
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AddAddress($address);

            $mail->SMTPDebug = 2;
            $mail->Debugoutput = 'html';


            $mail->Send();
    }
}
?>

And then

Mail::sendMail('New message', $body, $email);

This is the error I get:

SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I read the Troubleshooting but it didn't help. I also read help articles by Dreamhost, but they are vague.

I'm wondering if it's something specific to Dreamhost that I need to do?

Polina
  • 457
  • 1
  • 4
  • 8
  • 1
    The code you posted looks legit. I would try `$mail->Host = 'sub5.mail.dreamhost.com';` without the `ssl` to see if that changes anything. Also, make sure you're using the right username/password combo (at least, that's what screwed me up). Also, try `tls` instead of SSL. – Stefano Maffulli Jul 05 '17 at 16:10
  • 1
    Thanks! Actually I just solved it, it was `tls` that did it (and removing `ssl://`) – Polina Jul 05 '17 at 18:09

0 Answers0