Sending mail with phpmailer


#1

Hi. I am working on a site through which users can send each other secret emails. Unfortunately, when I use the regular php mail() function, while the emails send, they don’t make it to gmail users. I believe that gmail has blacklisted my server because it thinks they are spam. (They aren’t. The users send the emails themselves.) After reading some posts here on the subject, I have decided to try to use phpmailer and smtp instead. However, I don’t know how to set up smtp for my dreamhost domain. Here is my current code:
[php]
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = “smtp.mydomain.io”;
$mail->SMTPAuth = true;
$mail->Username = "mailer@mydomain.io";
$mail->Password = “mypassword”;
$mail->From = "mailer@mydomain.io";
$mail->FromName = “My Site Name”;
$mail->AddAddress($recipient);
$mail->AddReplyTo("noreply@mydomain.io", “No Reply”);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->Send())
{
echo "Message could not be sent.

";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo “Message has been sent”;
[/php]
Any idea how to get this to work?


#2

Do you have mailer@mydomain set up as a valid email address hosted at dreamhost?

are you seeing any errors? if so what is the error text?


#3

Yes, I am able to log in to webmail.mydomain.io with the username ‘mailer’ and the password ‘mypassword’.

The error I receive is:
[php]
Warning: substr() expects parameter 1 to be string, array given in /home/myname/mydomain/vendor/class.phpmailer.php on line 1627
SMTP Error: Could not connect to SMTP host. Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.
[/php]