我正在尝试从 php 向 gmail 帐户发送电子邮件。我的笔记本电脑上有以下设置:
- Windows 8
- Internet connection
- XAMPP 1.7.4, PHP Version 5.3.5,
我有以下 php.ini 设置
[mail function] ; For Win32 only. ; http://php.net/smtp SMTP = smtp.gmail.com ; http://php.net/smtp-port
smtp_port = :465
; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = postmaster@localhost
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
以下是php代码:
<?php
$to = 'goodmandiamont@gmail.com';
$subject = 'hi';
$msg = 'Test';
$headers = 'From: postmaster@localhost' ."\r\n" .
'Reply-To: shawn.danisa@gmail.com' . "\r\n" .
'X-Mailer: PHP /' . phpversion();
mail($to, $subject,$msg,$headers);
?>
我收到以下错误:
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first.
我还确保在 gmail 设置中启用了 IMAP 设置。我还检查了是否会在 php.ini 文件中找到以下行:
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
但运气不好,我只是找不到它们。请协助,我是 php 新手。
最佳答案
首先,确保您的 PHP 安装支持 SSL(在 phpinfo()
的输出中查找“openssl”部分)。
同样,您需要在 PHP 配置 PHP.ini 中设置以下设置
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
希望这能解决您的问题。
关于php mail function error -> Warning : mail() [function. mail] : SMTP server response: 530 5. 7.0 必须先发出STARTTLS命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20285056/