php.ini & SMTP= - 你如何传递用户名和密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/112190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php.ini & SMTP= - how do you pass username & password
提问by Charles Faiga
My ISPaccount requires that I send a username & password for outbound SMTPmail.
My ISP帐户要求我发送出站SMTP邮件的用户名和密码。
How do I get PHPto use this when executing php.mail()?The php.inifile only contains entries for the server (SMTP= )and From: (sendmail_from= ).
执行时如何PHP使用php.mail()?该php.ini文件仅包含服务器(SMTP= )和From: (sendmail_from= ).
采纳答案by daremon
回答by sugunan
I apply following details on php.ini file. its works fine.
我在 php.ini 文件上应用了以下详细信息。它的工作正常。
SMTP = smtp.example.com
smtp_port = 25
username = [email protected]
password = yourmailpassord
sendmail_from = [email protected]
These details are same as on outlook settings.
这些详细信息与 Outlook 设置相同。
回答by Henrik Rosvall
Use Fake sendmail for Windowsto send mail.
使用Fake sendmail for Windows发送邮件。
- Create a folder named
sendmailinC:\wamp\. - Extract these 4 files in
sendmailfolder:sendmail.exe,libeay32.dll,ssleay32.dllandsendmail.ini. - Then configure
C:\wamp\sendmail\sendmail.ini:
- 创建一个名为文件夹
sendmail在C:\wamp\。 - 在这些提取4个文件
sendmail夹:sendmail.exe,libeay32.dll,ssleay32.dll和sendmail.ini。 - 然后配置
C:\wamp\sendmail\sendmail.ini:
smtp_server=smtp.gmail.com smtp_port=465 [email protected] auth_password=your_password
smtp_server=smtp.gmail.com smtp_port=465 [email protected] auth_password=your_password
The above will work against a Gmail account. And then configure php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Now, restart Apache, and that is basically all you need to do.
以上将适用于 Gmail 帐户。然后配置php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
现在,重新启动 Apache,这基本上就是您需要做的全部工作。
回答by blavla
PHP doeshave authentication on the mail-command!
PHP确实对邮件命令进行了身份验证!
The following is working for me on WAMPSERVER (windows, php 5.2.17)
以下在 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 = [email protected]
回答by Jay Sudo
- Install Postfix (Sendmail-compatible).
- Edit
/etc/postfix/main.cfto read:
- 安装 Postfix(兼容 Sendmail)。
- 编辑
/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
- Create
/etc/postfix/sasl_passwd, enter:
- 创建
/etc/postfix/sasl_passwd,输入:
smtp.server.net username:password
Type #
/usr/sbin/postmap sasl_passwdThen run:
service postfix reload
类型 #
/usr/sbin/postmap sasl_passwd然后运行:
service postfix reload
Now PHP will run mail as usual with the sendmail -t -icommand and Postfix will intercept it and relay it to your SMTP server that you provided.
现在 PHP 将像往常一样使用该sendmail -t -i命令运行邮件,Postfix 将拦截它并将其中继到您提供的 SMTP 服务器。
回答by Eric_WVGG
I prefer the PHPMailertool as it doesn't require PEAR. But either way, you have a misunderstanding: you don't want a PHP-server-wide setting for the SMTP user and password. This should be a per-app (or per-page) setting. If you want to use the same account across different PHP pages, add it to some kind of settings.php file.
我更喜欢PHPMailer工具,因为它不需要 PEAR。但无论哪种方式,您都有一个误解:您不想要 SMTP 用户和密码的 PHP 服务器范围设置。这应该是每个应用程序(或每个页面)的设置。如果您想在不同的 PHP 页面上使用相同的帐户,请将其添加到某种 settings.php 文件中。
回答by B Seven
After working all day on this, I finally found a solution. Here's how I send from Windows XP with WAMP.
经过一整天的努力,我终于找到了解决方案。这是我使用 WAMP 从 Windows XP 发送的方法。
- Use Google's SMTP server. You probably need an account.
- Download and install Fake Sendmail. I just downloaded it, unzipped it and put it in the WAMP folder.
- Create a test PHP file. See below.
- 使用 Google 的 SMTP 服务器。您可能需要一个帐户。
- 下载并安装Fake Sendmail。我刚刚下载了它,解压缩并将其放入 WAMP 文件夹中。
- 创建一个测试 PHP 文件。见下文。
<?php $message = "test message body"; $result = mail('[email protected]', 'message subject', $message); echo "result: $result"; ?>
<?php $message = "test message body"; $result = mail('[email protected]', 'message subject', $message); echo "result: $result"; ?>
- Update your php.ini file and your sendmail.ini file (sendmail.ini is in the sendmail folder).
- Check the error.log file in the sendmail folder that you just created if it doesn't work.
- 更新您的 php.ini 文件和 sendmail.ini 文件(sendmail.ini 在 sendmail 文件夹中)。
- 如果它不起作用,请检查您刚刚创建的 sendmail 文件夹中的 error.log 文件。
Reference:
参考:
回答by Delino
These answers are outdated and depreciated. Best practice..
这些答案已过时且已贬值。最佳实践..
composer require phpmailer/phpmailer
The next on your sendmail.php file just require the following
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 = "[email protected]";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("[email protected]", "Recepient Name");
$mail->addAddress("[email protected]"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("[email protected]", "Reply");
//CC and BCC
$mail->addCC("[email protected]");
$mail->addBCC("[email protected]");
//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";
}
This can be configure how ever you like..
这可以根据您的喜好进行配置..
回答by William Keller
回答by Tamás Bolvári
- Install the latest hMailServer. "Run hMailServer Administrator" in the last step.
- Connect to "localhost".
- "Add domain..."
- Set "127.0.0.1." as the "Domain", click "Save".
- "Settings" > "Protocols" > "SMTP" > "Delivery of e-mail"
- Set "localhost" as the "Local host name", provide your data in the "SMTP Relayer" section, click "Save".
- "Settings" > "Advanced" > "IP Ranges" > "My Computer"
- Disable the "External to external e-mail addresses" checkbox in the "Require SMTP authentication" group.
- If you have modified php.ini, rewrite these 3 values:
- 安装最新的hMailServer。在最后一步中“运行 hMailServer Administrator”。
- 连接到“本地主机”。
- “添加域...”
- 设置“127.0.0.1” 作为“域”,单击“保存”。
- “设置”>“协议”>“SMTP”>“发送电子邮件”
- 将“localhost”设置为“本地主机名”,在“SMTP Relayer”部分提供您的数据,单击“保存”。
- “设置”>“高级”>“IP 范围”>“我的电脑”
- 禁用“需要 SMTP 身份验证”组中的“外部电子邮件地址”复选框。
- 如果你修改过php.ini,重写这3个值:
"SMTP = localhost",
"SMTP = 本地主机",
"smtp_port = 25",
"smtp_port = 25",
";sendmail_path = ".
" ;sendmail_path = "。
Credit: How to configure WAMP (localhost) to send email using Gmail?

