【发布时间】:2021-11-20 10:39:03
【问题描述】:
我正在处理一个需要发送电子邮件的项目。我的发送邮件功能是:
ini_set('sendmail_path', "\"C:\xampp\sendmail\sendmail.exe\" -t");
ini_set('smtp_server', 'smtp.gmail.com');
ini_set('smtp_port', 25);
ini_set('smtp_ssl', 'auto');
ini_set('error_logfile', 'error.log');
ini_set('auth_username', 'myemailAddreds@gmail.com');
ini_set('auth_password', 'mygmail_password');
//sendmail_from('myemailAddreds@gmail.com');
$to = 'myemailAddreds@gmail.com';
$subject = 'Hello from XAMPP!';
$message = 'This is a test';
$headers = "From: your@email-address.com\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "SUCCESS";
} else {
echo "ERROR";
}
但我收到以下错误
警告:mail():无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 C:\umtab\xampp 中使用 ini_set() \htdocs\umtab\email.php 第 23 行
【问题讨论】:
-
使用 PHPMailer 比直接从 PHP 连接到 SMTP 服务器要好得多,而不是在 sendmail 设置中添加一层复杂性
-
请告诉我们我们的解决方案是否适合您!