Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件功能:我必须停用防火墙吗?_Php_Xampp_Smtp_Phpmailer_Sendmail - Fatal编程技术网

PHP邮件功能:我必须停用防火墙吗?

PHP邮件功能:我必须停用防火墙吗?,php,xampp,smtp,phpmailer,sendmail,Php,Xampp,Smtp,Phpmailer,Sendmail,我正在使用xampp sendmail在本地主机中使用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= (

我正在使用xampp sendmail在本地主机中使用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到本地主机,因为它更快更安全。这还意味着您可以忽略php.ini中的所有mail和sendmail配置。试试这个:

$mail->isSMTP();
$mail->Host = 'localhost';
如果您没有可用的本地邮件服务器(这也解释了您在使用
mail()
时遇到问题的原因),请将
Host
属性改为指向托管提供商的邮件服务器-他们应该能够提供有关要使用的设置的文档。

示例:

使用PHPMailer\PHPMailer\PHPMailer;
使用PHPMailer\PHPMailer\Exception;
需要'path/to/PHPMailer/src/Exception.php';
需要'path/to/PHPMailer/src/PHPMailer.php';
需要'path/to/PHPMailer/src/SMTP.php';
$mail=新的PHPMailer(true);//传递'true'将启用异常
试一试{
//服务器设置
$mail->SMTPDebug=2;//启用详细调试输出
$mail->isSMTP();//设置邮件程序以使用SMTP
$mail->Host='smtp1.example.com;smtp2.example.com';//指定主SMTP服务器和备份SMTP服务器
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username=user@example.com“;//SMTP用户名
$mail->Password='secret';//SMTP密码
$mail->SMTPSecure='tls';//启用tls加密,也接受'ssl'
$mail->Port=587;//要连接的TCP端口
//接受者
$mail->setFrom('from@example.com","梅勒",;
$mail->addAddress('joe@example.net“,”Joe User');//添加收件人
$mail->addAddress('ellen@example.com');//名称是可选的
$mail->addReplyTo('info@example.com","信息",;
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
//附件
$mail->addAttachment('/var/tmp/file.tar.gz');//添加附件
$mail->addAttachment('/tmp/image.jpg','new.jpg');//可选名称
//内容
$mail->isHTML(true);//将电子邮件格式设置为HTML
$mail->Subject='主题在这里';
$mail->Body='这是以粗体显示的HTML邮件正文!';
$mail->AltBody='这是非HTML邮件客户端的纯文本正文';
$mail->send();
回音“消息已发送”;
}捕获(例外$e){
echo“无法发送消息”;
回显“邮件错误:”。$mail->ErrorInfo;
}
启用
openssl

php.ini
-
;extension=php_openssl.dll

您的
smtp
端口是否打开?@anderilupulesa是的,我打开了smtp端口(25),但仍然存在相同的错误。端口587:这是默认的邮件提交端口。当邮件客户端或服务器提交要由适当的邮件服务器路由的电子邮件时,它应该始终使用此端口。@AndreilupuleSA我应该从sendmail.ini文件中更改它吗?更改它并重试我收到以下错误:2019-04-18 14:05:42 SMTP connect()失败。无法发送邮件。邮件程序错误:SMTP connect()失败。链接上说可能是防火墙阻塞,我想这就是问题所在。您是否激活了
openssl
echo!已加载扩展(“openssl”)?“不可用”:“可用”
-
;extension=php_openssl.dll
我在php.ini中取消了该行的注释
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 = 'user@example.com';                 // 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('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    //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;
}