使用PHP从SMTP服务器发送电子邮件 [英] Sending email with PHP from an SMTP server
问题描述
$from = "someonelse@example.com";
$headers = "From:" . $from;
echo mail ("borutflis1@gmail.com" ,"testmailfunction" , "Oj",$headers);
我在PHP中发送电子邮件时遇到问题。我收到一个错误: SMTP服务器响应:530 SMTP验证需要
。
I have trouble sending email in PHP. I get an error: SMTP server response: 530 SMTP authentication is required
.
我的印象是你可以发送无SMTP的电子邮件进行验证。我知道这个邮件会被大量的滤掉,但是现在没关系。
I was under the impression that you can send email without SMTP to verify. I know that this mail will propably get filtered out, but that doesn't matter right now.
[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服务器不需要验证,还是自己设置一个服务器?
This is the setup in the php.ini
file. How should I set up SMTP? Are there any SMTP servers that require no verification or must I setup a server myself?
推荐答案
发送电子邮件时通过需要SMTP认证的服务器,您真的需要指定它,并设置主机,用户名和密码(也可能是端口,如果不是默认端口)。
When you are sending an e-mail through a server that requires SMTP Auth, you really need to specify it, and set the host, username and password (and maybe the port if it is not the default one - 25).
例如,我通常使用PHPMailer与此类似的设置:
For example, I usually use PHPMailer with similar settings to this ones:
$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
You can find more about PHPMailer here: https://github.com/PHPMailer/PHPMailer
这篇关于使用PHP从SMTP服务器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!