PHP - 从另一台服务器通过phpMailer发送电子邮件

时间:2018-03-10 19:13:11

标签: php smtp phpmailer

我尝试发送来自服务器2 的电子邮件,并在服务器1

直接管理员中打开电子邮件

我试过这样:

public function send() {
    $mail             = new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.server1.com"; // SMTP server
    $mail->SMTPDebug  = true;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Username   = "name@server1.com";
    $mail->Password   = "pass";
    $mail->SetFrom('name@server1.com', 'name');
    $mail->AddReplyTo("name@server1.com","name");
    $mail->Subject    = $this->subj;
    $mail->MsgHTML($this->msg);
    $address = $this->mailTo;
    $address = explode(',', $address);
    foreach($address as $k=>$v) {
        $mail->AddAddress($v);
    }
    $mail->CharSet = 'UTF-8';
    $mail->Send();
}

这个功能我在server2.com运行。

我收到了一个错误:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
<br />SMTP Error: Could not connect to SMTP host.

我能做什么?

1 个答案:

答案 0 :(得分:0)

您可能缺少参数:

$mail->SMTPSecure // can be 'tls' or 'ssl'
$mail->Port // can be '587' to TLS or '465' to SSL