我正在尝试在注册后向注册用户发送邮件。
为此,我正在使用 phpmailer 库。
我的代码如下:
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$username = "xyz@demo.net";
$password = "1234567";
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = $username;
$mail->Password = $password;
$mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
$mail->IsHTML(true);
$mail->WordWrap = 900;
if (!$mail->Send()) {
$error = 'Mail error: ' . $mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
$mail->SmtpClose();
return true;
}
此代码在 localhost 上运行良好,但我将其上传到 mysite 然后显示以下错误:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed.
我的网站托管在文件夹中,例如(myhost.in/mysite)。
请帮我找出问题并解决它
提前致谢...