我正在使用xampp sendmail在我的localhost中使用php制作邮件发件人。
我按原样配置了sendmail.ini和php.ini文件,但我仍然在errol.log文件中收到此错误:
19/04/18 13:51:58:套接字错误#10013访问被拒绝。
当我搜索时,我发现我必须停用防火墙,但我正在管理防火墙。
还有其他方法吗?
我在sendmail.ini上做的配置:
smtp_server= smtp.gmail.com
smtp_ssl=tls
auth_username= (my email)
auth_password= (my email's password)
force_sender= (my email)
hostname= localhost
我在php.ini上做的配置:
;SMTP = localhost
sendmail_path = C:\xampp\sendmail\sendmail.exe
避免在PHPMailer中使用mail()
(默认)和sendmail(使用isSendmail()
)传输;使用SMTP代替localhost,因为它更快更安全。这也意味着您可以忽略php.ini中的所有邮件和sendmail配置。试试这个:
$mail->isSMTP();
$mail->Host = 'localhost';
如果您没有可用的本地邮件服务器(这也可以解释为什么您在使用mail()
时遇到问题),请将Host
属性更改为指向您的托管服务提供商的邮件服务器 - 他们应该能够提供有关设置的文档使用。
https://github.com/Synchro/PHPMailer的示例:
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); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
启用openssl
在php.ini
- ;extension=php_openssl.dll