My ISP
帐户要求我发送用户名&出站SMTP
邮件的密码。
如何在执行PHP
时php.mail()?
使用此php.ini
(SMTP= )
文件仅包含服务器From: (sendmail_from= )
和{{1}}的条目。
答案 0 :(得分:40)
PHP mail()
命令不支持身份验证。你的选择:
答案 1 :(得分:38)
我在php.ini文件中应用以下详细信息。它的工作正常。
SMTP = smtp.example.com
smtp_port = 25
username = info@example.com
password = yourmailpassord
sendmail_from = info@example.com
这些细节与展望设置相同。
答案 2 :(得分:17)
使用Fake sendmail for Windows发送邮件。
sendmail
。C:\wamp\
的文件夹
sendmail
文件夹中提取这4个文件:sendmail.exe
,libeay32.dll
,ssleay32.dll
和sendmail.ini
。C:\wamp\sendmail\sendmail.ini
:smtp_server=smtp.gmail.com smtp_port=465 auth_username=user@gmail.com auth_password=your_password
以上内容适用于Gmail帐户。然后配置php.ini:
sendmail_path =“C:\ wamp \ sendmail \ sendmail.exe -t”
现在,重新启动Apache,这基本上就是你需要做的。
答案 3 :(得分:12)
PHP 确实对mail-command进行身份验证!
以下内容适用于WAMPSERVER(windows,php 5.2.17)
的php.ini
[mail function]
; For Win32 only.
SMTP = mail.yourserver.com
smtp_port = 25
auth_username = smtp-username
auth_password = smtp-password
sendmail_from = you@yourserver.com
答案 4 :(得分:5)
我更喜欢PHPMailer工具,因为它不需要PEAR。但无论哪种方式,您都有一个误解:您不希望为SMTP用户和密码设置PHP服务器范围。这应该是每个应用程序(或每页)设置。如果要在不同的PHP页面中使用相同的帐户,请将其添加到某种settings.php文件中。
答案 5 :(得分:5)
在这一整天工作之后,我终于找到了解决方案。以下是我使用WAMP从Windows XP发送的方式。
<?php $message = "test message body"; $result = mail('recipient@some-domain.com', 'message subject', $message); echo "result: $result"; ?>
参考:
答案 6 :(得分:5)
/etc/postfix/main.cf
以阅读:#Relay config
relayhost = smtp.server.net
smtp_use_tls=yes
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_sasl_security_options = noanonymous
/etc/postfix/sasl_passwd
,输入:smtp.server.net username:password
输入#/usr/sbin/postmap sasl_passwd
然后运行:service postfix reload
现在PHP将使用sendmail -t -i
命令照常运行邮件,Postfix将拦截它并将其转发到您提供的SMTP服务器。
答案 7 :(得分:2)
在Mail PEAR包中使用Mail :: factory。 Example.
答案 8 :(得分:2)
这些答案已过时并已折旧。 最佳实践..
composer require phpmailer/phpmailer
sendmail.php文件中的下一个文件只需要以下内容
# use namespace
use PHPMailer\PHPMailer\PHPMailer;
# require php mailer
require_once "../vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");
$mail->addAddress("recepient1@example.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply");
//CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
这可以配置你喜欢的..
答案 9 :(得分:0)
在this question中考虑一个答案,在PHP 4中,PEAR Mail软件包通常已经安装,这个非常简单的教程向您展示了需要添加到php文件中的几行代码{{3} }
答案 10 :(得分:0)
“SMTP = localhost”,
“smtp_port = 25”,
“; sendmail_path =”。
信用:How to configure WAMP (localhost) to send email using Gmail?