php.ini& SMTP = - 你如何通过用户名&密码

时间:2008-09-21 21:11:35

标签: php smtp email

My ISP帐户要求我发送用户名&出站SMTP邮件的密码。

如何在执行PHPphp.mail()?使用此php.ini (SMTP= )文件仅包含服务器From: (sendmail_from= )和{{1}}的条目。

11 个答案:

答案 0 :(得分:40)

PHP mail()命令不支持身份验证。你的选择:

  1. PHPMailer - Tutorial
  2. PEAR - Tutorial
  3. 自定义功能 - 请参阅备注部分中的各种解决方案:http://php.net/manual/en/ref.mail.php

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

  1. sendmail
  2. 中创建名为C:\wamp\的文件夹
  3. sendmail文件夹中提取这4个文件:sendmail.exelibeay32.dllssleay32.dllsendmail.ini
  4. 然后配置C:\wamp\sendmail\sendmail.ini
  5. smtp_server=smtp.gmail.com
    smtp_port=465
    auth_username=user@gmail.com
    auth_password=your_password
    
    1. 以上内容适用于Gmail帐户。然后配置php.ini:

        

      sendmail_path =“C:\ wamp \ sendmail \ sendmail.exe -t”

    2. 现在,重新启动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发送的方式。

  1. 使用Google的SMTP服务器。您可能需要一个帐户。
  2. 下载并安装Fake Sendmail。我刚刚下载了它,解压缩并将其放入WAMP文件夹。
  3. 创建测试PHP文件。见下文。
  4. <?php
        $message = "test message body";
        $result = mail('recipient@some-domain.com', 'message subject', $message);
        echo "result: $result";
    ?>
    
    1. 更新您的php.ini文件和sendmail.ini文件(sendmail.ini位于sendmail文件夹中)。
    2. 检查刚刚创建的sendmail文件夹中的error.log文件,如果它不起作用。
    3. 参考:

答案 6 :(得分:5)

  1. 安装Postfix(与Sendmail兼容)。
  2. 修改/etc/postfix/main.cf以阅读:
  3. #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. 创建/etc/postfix/sasl_passwd,输入:
    2. smtp.server.net username:password
      
      1. 输入#/usr/sbin/postmap sasl_passwd

      2. 然后运行:service postfix reload

      3. 现在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)

  1. 安装最新的hMailServer。 “在最后一步中运行hMailServer Administrator”。
  2. 连接到“localhost”。
  3. “添加域名...”
  4. 设置“127.0.0.1。”作为“域名”,点击“保存”。
  5. “设置”&gt; “协议”&gt; “SMTP”&gt; “发送电子邮件”
  6. 将“localhost”设置为“本地主机名”,在“SMTP Relayer”部分提供您的数据,然后点击“保存”。
  7. “设置”&gt; “高级”&gt; “IP范围”&gt; “我的电脑”
  8. 禁用“要求SMTP身份验证”组中的“外部到外部电子邮件地址”复选框。
  9. 如果您修改了php.ini,请重写这3个值:
  10. “SMTP = localhost”,

    “smtp_port = 25”,

    ; sendmail_path =”。

    信用:How to configure WAMP (localhost) to send email using Gmail?