问题现象
php.ini邮件配置正确但不发送邮件。报错如下
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first 
 
问题原因
php mail()函数不可用,需要安装sendmail 。
 
解决方案
1.从
http://glob.com.au/sendmail/下载sendmail.zip 
2.解压到C:下,例如:【C:\php\sendmail】最好短路径,长路径名有可能产生问题。 
3.修改【php.ini】如下 
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t" 
4.根据自己的配置环境修改【sendmail.ini】。 
第一次最好启用debug.log_file,error_logfile,以查看sendmail是否生效。 
5.重启apache 
用sendmail结合其它的smtp服务器,如smtp.163.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。 
php.ini配置 (以用163邮箱为例) 
[mail function]; For Win32 only.SMTP = smtp.163.comsmtp_port = 25; For Win32 …… 
用sendmail结合其它的smtp服务器,如smtp.163.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。 
php.ini配置 (以用163邮箱为例) 
[mail function]; For Win32 only.SMTP = smtp.163.comsmtp_port = 25; For Win32 only.sendmail_from = 4u4v@163.com; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).sendmail_path = “D:\xampp\sendmail\sendmail.exe -t”
主要配置三项,【smtp】、【smtp_port】和【sendmail_path】 
【sendmail.ini】配置 
[sendmail]; you must change mail.mydomain.com to your smtp serversmtp_server=smtp.163.comsmtp_port=25auth_username=yourusernameauth_password=yourpasswordforce_sender=yourusername@163.com 
以上都是已163为例子的,请更具自己的实际需要修改自己的邮箱配置。
 
 
如果问题还未能解决,请联系
售后技术支持。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
您的解决方案已经很详细了,这里我再补充一些使用阿里云产品进行邮件发送的建议,这或许能为您提供另一种解决思路。
阿里云提供了邮件服务——阿里云邮件推送(DirectMail),它支持API调用和SMTP服务,可以方便地集成到您的PHP应用中。相较于自建邮件发送系统或使用第三方SMTP服务器,使用阿里云DirectMail有以下优势:
如果您还没有阿里云账号,首先需要注册一个,并在控制台开通DirectMail服务。
这些凭证是调用阿里云API时的身份验证信息,需妥善保管。
在DirectMail控制台创建一个用于发送邮件的域名,并完成域名解析验证。
php.ini配置文件,使用阿里云提供的SMTP服务代替之前的配置:
[mail function]
SMTP = smtpdm.aliyun.com
smtp_port = 465
sendmail_from = your_email@example.com
; 如果需要SSL加密
smtp_ssl = ssl
使用PHPMailer库配合阿里云SMTP服务发送邮件,确保您已安装PHPMailer库。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
try {
    // 服务器设置
    $mail->SMTPDebug = 0;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Set mailer to use SMTP
    $mail->Host       = 'smtpdm.aliyun.com';                    // Specify main and backup SMTP servers
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'your_email@example.com';                     // SMTP username
    $mail->Password   = 'your_smtp_authorization_code';                               // SMTP password
    $mail->SMTPSecure = 'ssl';            // Enable TLS encryption, `ssl` also accepted
    $mail->Port       = 465;                                    // TCP port to connect to
    // Recipients
    $mail->setFrom('your_email@example.com', 'Mailer');
    $mail->addAddress('recipient@example.com', 'Recipient');     // Add a recipient
    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
通过上述方式,您可以利用阿里云的DirectMail服务来替代传统的sendmail或自建SMTP服务器,以更稳定、高效的方式发送邮件。