" SMTP connect()失败"。配置它以从远程主机发送电子邮件时

时间:2016-12-01 07:17:06

标签: php email smtp xampp

我是PHP新手。我使用PHPMailer发送电子邮件但无法这样做。我尝试为gmail配置它并且它工作但是当试图从远程主机和给定域发送消息时不工作。 这是代码。

<?php  

       require("PHPMailerAutoload.php"); // path to the PHPMailerAutoload.php file.

       $mail = new PHPMailer();
       //$mail->IsSMTP();
       $mail->Mailer = "smtp";
       $mail->Host = "175.000.000.000"; //Sample Host
       $mail->SMTPDebug = 1;
       $mail->Port = "25"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
       $mail->SMTPAuth = true;
       //$mail->SMTPSecure = 'ssl';
       $mail->Username = "maaz@mcbah.com";
       $mail->Password = "password";

       $mail->From     = "maaz@mcbah.com";
       $mail->FromName = "Maaz Khan";
       $mail->AddAddress("mcbah.all@mcbah.com", "all");
       $mail->AddReplyTo("fundprices@mcbah.com", "Fund");

       $mail->Subject  = "Hi!";
       $mail->Body     = "Hi! How are you?";
       $mail->WordWrap = 50;  

       if(!$mail->Send()) {
            echo 'Message was not sent.';
            echo 'Mailer error: ' . $mail->ErrorInfo;
                    echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>';
            exit;
       } else {
            echo 'Message has been sent.';
       }

1 个答案:

答案 0 :(得分:0)

此代码可以帮助您

  

$ mail-&gt; Host =“smtpout.secureserver.net”;

Your host name should be like mydomain.com
  

$ mail-&gt; Port = 465;