5.7.0必须先发出STARTTLS命令.windows 7


SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. windows 7

我使用的是windows 7,我试图在php中使用mail()函数发送电子邮件。我写了很多,试了很多,但仍然不能发送。这是我的代码:

 ini_set("SMTP","smtp.gmail.com");
ini_set("smtp_port","25");

$to = 'asdf@gmail.com';
$subject = 'hi';
$msg = 'Test';
$headers ='Reply-To: shawn.danisa@gmail.com' . "'r'n" .
        'From: postmaster@localhost' ."'r'n" .
        'X-Mailer: PHP /' . phpversion();
mail($to, $subject,$msg,$headers);

得到:

  SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. x42sm11770579eel.41 - gsmtp

我尝试使用端口587,但然后我得到:

    SMTP server response: 530 5.7.0 Must issue a STARTTLS command first.      y51sm11859758eeu.0 

请帮助端口465我的页面甚至不加载。我还是用windows 7

使用Swiftmailer之类的库来为您处理此问题:http://swiftmailer.org/docs/sending.html