题
My ISP
帐户要求我给一个用户名和密码对出站 SMTP
邮件。
我怎么得到的 PHP
使用这个当执行 php.mail()?
的 php.ini
文件仅含有条目的服务器 (SMTP= )
和 From: (sendmail_from= )
.
解决方案
PHP mail()
命令不支持身份验证。你的选择:
- PHPMailer - 教程
- PEAR - 教程
- 自定义功能 - 请参阅备注部分中的各种解决方案: http://php.net /manual/en/ref.mail.php 醇>
其他提示
我在php.ini文件中应用以下详细信息。它的工作正常。
SMTP = smtp.example.com
smtp_port = 25
username = info@example.com
password = yourmailpassord
sendmail_from = info@example.com
这些细节与展望设置相同。
使用用于Windows的假sendmail 发送邮件。
- 在
C:\ wamp \
中创建名为sendmail
的文件夹。 - 在
sendmail
文件夹中提取这4个文件:sendmail.exe
,libeay32.dll
,ssleay32.dll
和sendmail.ini
。 - 然后配置
C:\ wamp \ sendmail \ sendmail.ini
:
醇>
-
以上内容适用于Gmail帐户。然后配置php.ini:
sendmail_path =" C:\ wamp \ sendmail \ sendmail.exe -t"
-
现在,重新启动Apache,这基本上就是你需要做的。
醇>
smtp_server=smtp.gmail.com smtp_port=465 auth_username=user@gmail.com auth_password=your_password
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
我更喜欢 PHPMailer 工具,因为它不需要PEAR。但无论哪种方式,您都有一个误解:您不希望为SMTP用户和密码设置PHP服务器范围。这应该是每个应用程序(或每页)设置。如果要在不同的PHP页面中使用相同的帐户,请将其添加到某种settings.php文件中。
后工作整天在这,我终于找到一个解决方案。这里就是我送从Windows XP*瓦姆普的办公室.
- 使用谷歌的SMTP server。你可能需要一个帐户。
- 下载,安装 假Sendmail.我刚刚下载它,打开它,并把它放在WAMP的文件夹。
- 创建一个测试PHP文件。见下文。
<?php $message = "test message body"; $result = mail('recipient@some-domain.com', 'message subject', $message); echo "result: $result"; ?>
- 更新你的php.ini文件和你的sendmail.ini文件(sendmail.ini是在sendmail文件夹)。
- 检查的错误。登录文件的sendmail文件夹,你刚刚创建,如果它不起作用。
参考:
- 安装Postfix(与Sendmail兼容)。
- 编辑
/etc/postfix/main.cf
以阅读:
醇>
- 创建
/ etc / postfix / sasl_passwd
,输入:
醇>
-
输入#
/ usr / sbin / postmap sasl_passwd
-
然后运行:
service postfix reload
醇>
#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
smtp.server.net username:password
现在PHP将像往常一样使用 sendmail -t -i
命令运行邮件,Postfix将拦截它并将其转发到您提供的SMTP服务器。
在Mail PEAR包中使用Mail :: factory。 示例。
这些答案已过时并已折旧。 最佳实践..
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";
}
这可以配置你喜欢的..
在这个问题中考虑一个答案,在PHP 4中,PEAR Mail包是通常已安装,这个非常简单的教程向您展示了需要添加到php文件的几行代码 http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
- 安装最新的 hMailServer."运行hMailServer管理员"在最后一个步骤。
- 连接到"localhost"。
- "增添域的..."
- 设置"127.0.0.1",将"领域",点击"保存"。
- "设置">"协议">"SMTP">"递送的电子邮件"
- 设置"localhost"作为"地主机名称", 提供数据在"SMTP rel ayer"部分, 点击"保存"。
- "设置">"高级">"知识产权的范围">"我的计算机"
- 禁用"外部到外部电子邮件地址"框中的"需要SMTP认证"组。
- 如果你有修改php.ini,改写这3值:
"SMTP=localhost",
"smtp_port=25",
"; sendmail_path=".