0

I'm new to website development and using Linux+Apache+PHP for my website and want to use PHPMailer to send e-mail. This is my code for index.php:

<?php
header("content-type:text/html;charset=utf-8");
date_default_timezone_set("Etc/GMT-8");

require_once"class.smtp.php";
require_once"class.phpmailer.php";

$mail = new PHPMailer;
$mail->IsSMTP();                  // send via SMTP
$mail->Host = "smtpdm.aliyun.com";   // SMTP servers
$mail->PORT = 465;
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->Username = "web@info.jingdaninternet.com";  // SMTP username
$mail->Password = "Mypassord"; // SMTP password
$mail->From = "web@info.jingdaninternet.com";
$mail->FromName =  "Test";
$mail->CharSet = "UTF-8";
$mail->Encoding = "base64";
$mail->AddAddress("info@jingdaninternet.com","Receiver");
$mail->IsHTML(true);  // send as HTML
$mail->Subject = "New Message";
$mail->Body = "Test";

if(!$mail->Send())
{
    echo "Wrong!";
    exit;
}
else {
    echo "Success!";
}

This script works on localhost, but when I upload this to server it doesn't work and shows:

SMTP ERROR: Failed to connect to server : Connection timed out (110).

Does anyone know how to solve this problem? Thanks!

Synchro
  • 35,538
  • 15
  • 81
  • 104
William
  • 1
  • 1
  • 2
  • 1
    You can refer to https://stackoverflow.com/questions/23782689/smtp-error-failed-to-connect-to-server-connection-timed-out-110-with-phpmail – hanish singla Aug 09 '17 at 11:14
  • 1
    You've based your code on an an obsolete example and it's got some basic things missing. Make sure you have [the latest version](https://github.com/PHPMailer/PHPMailer), use an up to date example, and read [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). You're missing `SMTPSecure = 'ssl'`, which is required if you're connecting to port 465. Aside from that, your ISP may be blocking your connection. All of this is covered in the guide. – Synchro Aug 09 '17 at 11:52
  • Problem solved!! Thanks for your help! – William Aug 10 '17 at 05:39

0 Answers0