发布日期:2018-03-26
如何用PHP通过SMTP服务器发邮件?+ 查看更多
如何用PHP通过SMTP服务器发邮件?
+ 查看更多
发布日期:2018-03-10 16:04
分类:PHP
浏览次数:110
$from = "someonelse@example.com"; $headers = "From:" . $from; echo mail ("borutflis1@gmail.com" ,"testmailfunction" , "Oj",$headers);
我无法在PHP中发送电子邮件。我收到一个错误:SMTP服务器响应:530需要SMTP验证。
在我的印象中,你可以发送没有SMTP的电子邮件进行验证。我知道这个邮件会被过滤掉,但是现在这并不重要。
在我的印象中,你可以发送没有SMTP的电子邮件进行验证。我知道这个邮件会被过滤掉,但是现在这并不重要。
[mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = someonelse@example.com
这是php.ini文件中的设置。如何设置SMTP?有没有任何SMTP服务器不需要验证或者我必须自己设置一个服务器?
例如,我通常使用PHPMailer类似的设置:
回答:
当你通过需要SMTP验证的服务器发送电子邮件时,您真的需要指定它,并设置主机,用户名和密码(如果不是默认端口25)。例如,我通常使用PHPMailer类似的设置:
$mail = new PHPMailer(); $mail->IsSMTP(); $mail->CharSet = 'UTF-8'; $mail->Host = "mail.example.com"; // SMTP server example $mail->SMTPDebug = 0; // enables SMTP debug information (for testing) $mail->SMTPAuth = true; // enable SMTP authentication $mail->Port = 25; // set the SMTP port for the GMAIL server $mail->Username = "username"; // SMTP account username example $mail->Password = "password"; // SMTP account password example你可以在这里找到更多关于PHPMailer的信息: https://github.com/PHPMailer/PHPMailer