如果您在 Gmail 帐户上启用了 SSL,则端口号为 587。我相信另一个是 465,根据帮助文档:https ://support.google.com/mail/answer/78775?hl=en
如果您尝试在端口 465(使用 SSL)和端口 587(使用 TLS)上配置 SMTP 服务器,但仍然无法发送邮件,请尝试将您的 SMTP 配置为使用端口 25(使用 SSL)。
您可能还应该使用 try/catch 块 - 如果 sendmail 因错误而失败,您可以 print_r 或 var_dump 查看异常消息包含的内容。
我应该承认我从未直接使用过 sendmail。我发现 Rmail 库更易于使用:
<?php
require_once( ROOT . DS . "libs" . DS . "Rmail" . DS . "Rmail.php" );
// Instantiate a new HTML Mime Mail object
$mail = new Rmail();
$mail->setSMTPParams($host = 'smtp.gmail.com', $port = 587, $helo = null, $auth = true, $user = 'gmail address', $pass = 'password');
// Set the From and Reply-To headers
$mail->setFrom( "Proper Name <send from email address>" );
$mail->setReturnPath( "reply email address" );
// Set the Subject
$mail->setSubject( 'Email subject/title' );
$html = 'you email message content';
// Create the HTML e-mail
$mail->setHTML( $html );
// Send the e-mail
$result = $mail->send( array( 'target email address' ) );
?>
如果您更愿意使用上面的代码片段,我可以在某个地方找到该库。