PHP邮件功能

时间:2010-12-21 13:43:33

标签: php

是否可以在没有任何外部软件包或工具的情况下使用PHP发送邮件?如果是的话,那么

配置php.ini文件的任何要求?

如下:

$to = $row->EMail_ID;
$subject = "Reset your password";
$body = "Hi ".$row->Username.", \n\t\t\tA request to reset your  password was received from you. \n\n\n";
$headers = "From: admin@admin.com\r\n"."X-Mailer: php/";
mail($to, $subject, $body, $headers); 

我得到的错误:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, 
verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in F:\wamp\www\pwd.php on line 20

4 个答案:

答案 0 :(得分:0)

听起来你没有安装sendmail(或其中一个替代品,如postfix或courier)。

答案 1 :(得分:0)

您没有在本地运行的邮件服务器,或者它使用非标准设置运行。

您可以查看phpinfo()的输出以获取有关您的邮件系统的信息。具体做法是:

sendmail_path  /usr/sbin/sendmail -t -i
SMTP           localhost
smtp_port      25

如果您使用的是共享主机,您的托管服务提供商可能会提供有关如何发送邮件的文档 - 这可能需要您使用PEAR /第三方库。

答案 2 :(得分:0)

是的,当然,正如他在我上面说的那样,但我会扩展他的榜样。

$mailto = "receiver@mail.com"
$mailfrom = "sender@mail.com"
$subject = "The subject of the mail"
$content = "The content of the mail"

$headers = "From: $mailfrom\r\n" .
    "Reply-To: $mailfrom\r\n" .
    "Content-type: text/html; charset=iso-8859-1\r\n" .
    'X-Mailer: PHP/' . phpversion();

$mailsuccess = mail($mailto,$subject,$content,$headers);

if($mailsuccess)
{
    echo 'Mail Sent!';
}
else
{
    echo 'Failed to send Mail!';
}

请注意标题中的Content-Type条目。离开它会使它只是默认为纯文本邮件,将该行设置为text / html的内容类型,允许您在邮件内容中使用html。您可以将from和reply-line设置为您想要的任何内容,并且标题还有其他选项,例如Important Flag和所有这些选项。此外,如果您想通过姓名和地址发送,您可以执行“Fname Lname< address@mail.com>”在标题中。

答案 3 :(得分:-3)

是的,邮件功能是内部功能。

不,你不必配置php.ini

<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// Send
mail('caffinated@example.com', 'My Subject', $message);
?>

如果要在本地服务器上进行检查,则必须安装邮件服务器。

相关问题