Php SMTP服务器响应:530 5.7.0必须首先发出STARTTLS命令。视窗7

Php SMTP服务器响应:530 5.7.0必须首先发出STARTTLS命令。视窗7,php,email,send,Php,Email,Send,我正在使用Windows7,我正在尝试用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" .

我正在使用Windows7,我正在尝试用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的库可以为您处理此问题:

您需要先“登录”,即internet上有一些脚本(与上面的脚本非常相似),其中包括用户名和密码。这是为了阻止人们滥用邮件服务器。