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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:29:45  来源:igfitidea点击:

php.ini & SMTP= - how do you pass username & password

phpsmtpemail

提问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

PHP mail()command does not support authentication. Your options:

PHPmail()命令不支持身份验证。您的选择:

  1. PHPMailer- Tutorial
  2. PEAR- Tutorial
  3. Custom functions - See various solutions in the notes section: http://php.net/manual/en/ref.mail.php
  1. PHPMailer-教程
  2. -教程
  3. 自定义函数 - 在注释部分查看各种解决方案:http: //php.net/manual/en/ref.mail.php

回答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发送邮件。

  1. Create a folder named sendmailin C:\wamp\.
  2. Extract these 4 files in sendmailfolder: sendmail.exe, libeay32.dll, ssleay32.dlland sendmail.ini.
  3. Then configure C:\wamp\sendmail\sendmail.ini:
  1. 创建一个名为文件夹sendmailC:\wamp\
  2. 在这些提取4个文件sendmail夹:sendmail.exelibeay32.dllssleay32.dllsendmail.ini
  3. 然后配置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
  1. The above will work against a Gmail account. And then configure php.ini:

    sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

  2. Now, restart Apache, and that is basically all you need to do.

  1. 以上将适用于 Gmail 帐户。然后配置php.ini:

    sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

  2. 现在,重新启动 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

  1. Install Postfix (Sendmail-compatible).
  2. Edit /etc/postfix/main.cfto read:
  1. 安装 Postfix(兼容 Sendmail)。
  2. 编辑/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
  1. Create /etc/postfix/sasl_passwd, enter:
  1. 创建/etc/postfix/sasl_passwd,输入:
smtp.server.net username:password
  1. Type # /usr/sbin/postmap sasl_passwd

  2. Then run: service postfix reload

  1. 类型 # /usr/sbin/postmap sasl_passwd

  2. 然后运行: 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 发送的方法。

  1. Use Google's SMTP server. You probably need an account.
  2. Download and install Fake Sendmail. I just downloaded it, unzipped it and put it in the WAMP folder.
  3. Create a test PHP file. See below.
  1. 使用 Google 的 SMTP 服务器。您可能需要一个帐户。
  2. 下载并安装Fake Sendmail。我刚刚下载了它,解压缩并将其放入 WAMP 文件夹中。
  3. 创建一个测试 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";
?>
  1. Update your php.ini file and your sendmail.ini file (sendmail.ini is in the sendmail folder).
  2. Check the error.log file in the sendmail folder that you just created if it doesn't work.
  1. 更新您的 php.ini 文件和 sendmail.ini 文件(sendmail.ini 在 sendmail 文件夹中)。
  2. 如果它不起作用,请检查您刚刚创建的 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

Use Mail::factory in the Mail PEAR package. Example.

使用 Mail PEAR 包中的 Mail::factory。例子。

回答by Tamás Bolvári

  1. Install the latest hMailServer. "Run hMailServer Administrator" in the last step.
  2. Connect to "localhost".
  3. "Add domain..."
  4. Set "127.0.0.1." as the "Domain", click "Save".
  5. "Settings" > "Protocols" > "SMTP" > "Delivery of e-mail"
  6. Set "localhost" as the "Local host name", provide your data in the "SMTP Relayer" section, click "Save".
  7. "Settings" > "Advanced" > "IP Ranges" > "My Computer"
  8. Disable the "External to external e-mail addresses" checkbox in the "Require SMTP authentication" group.
  9. If you have modified php.ini, rewrite these 3 values:
  1. 安装最新的hMailServer。在最后一步中“运行 hMailServer Administrator”。
  2. 连接到“本地主机”。
  3. “添加域...”
  4. 设置“127.0.0.1” 作为“域”,单击“保存”。
  5. “设置”>“协议”>“SMTP”>“发送电子邮件”
  6. 将“localhost”设置为“本地主机名”,在“SMTP Relayer”部分提供您的数据,单击“保存”。
  7. “设置”>“高级”>“IP 范围”>“我的电脑”
  8. 禁用“需要 SMTP 身份验证”组中的“外部电子邮件地址”复选框。
  9. 如果你修改过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?

信用:如何配置 WAMP(本地主机)以使用 Gmail 发送电子邮件?