SMTP邮件的SMTPconfiguration

我通过使用PHP邮件function从我的网站发送邮件。 但现在它不工作,我联系了我们的托pipe团队,然后他们告诉我使用smtp,因为他们做了一些服务器的变化。 我不知道该怎么做 目前的代码(与PHP邮件function)如下,任何人都可以帮助我的变化,我必须做到这一点。

<?php $mail_To="someone@gmail.com"; $headers = ""; $headers .= "From: livetv@muscle-tube.com\n"; $headers .= "Reply-To: livetv@muscle-tube.com\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "X-Mailer: php"; $mail_Subject = " Live TV key"; $mail_Body = "<p>Muscle-tube</p>"; mail($mail_To, $mail_Subject, $mail_Body,$headers); 

?>

PHP的mail()函数不支持SMTP。 你将需要使用像PEAR邮件包的东西。

这是一个示例SMTP邮件脚本:

 <?php require_once("Mail.php"); $from = "Your Name <email@blahblah.com>"; $to = "Their Name <otheremail@whatever.com>"; $subject = "Subject"; $body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit..."; $host = "mailserver.blahblah.com"; $username = "smtp_username"; $password = "smtp_password"; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if ( PEAR::isError($mail) ) { echo("<p>Error sending mail:<br/>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message sent.</p>"); } ?> 

但现在它不工作,我联系了我们的托pipe团队,然后他们告诉我使用smtp

快讯 – 之前使用SMTP。 他们没有提供你需要的信息来解决问题,或者你没有在这里准确地传达信息。

他们可能已经禁用了networking服务器上的本地MTA,在这种情况下,您需要连接远程机器上的SMTP端口。 有很多工具包可以为你做繁重的工作。 我个人喜欢phpmailer,因为它增加了其他function。

当然,如果他们已经拿走了以前那里的一个设施,并且为了一个服务付费,那么你的提供商应该给你比这更好的支持(也有很多程序可以代替完整的MTA来完成工作)。

C。

请注意,PHP邮件设置来自你的php.ini文件。 默认看起来或多或less像这样:

 [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = me@example.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename mail.add_x_header = On ; Log all mail() calls including the full path of the script, line #, to address and headers ;mail.log = 

通过编辑你的php.ini文件,你应该能够解决这个问题而不用改变你的PHP脚本。 另外,如果直接连接到SMTP服务器,则可以使用telnet工具和HELO,MAIL FROM,RCPT TO,DATA,QUIT命令testing连接。 使用sendmail,你甚至不需要,sendmail应该知道它在做什么(尽pipe在你的情况下,它可能不是,sendmail设置可能需要一些帮助。)

由于这里给出的一些答案涉及到一般设置SMTP(而不仅仅是@shinod特定的问题,它已经工作和停止),我认为这将是有益的,如果我更新了答案,因为这是很简单的现在做比它曾经是:-)

在PHP 4中,PEAR Mail包通常已经安装好了,这个非常简单的教程向你展示了你需要添加到你的php文件中的几行代码http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication热媒;

大多数托pipe公司列出您需要的SMTP设置。 我使用JustHost,并在https://my.justhost.com/cgi/help/26 (在发送邮件服务器下)

PHP的email()函数将电子邮件转移到底层的mail transfer agent ,这通常是在Linux系统上的postfix

所以linux上的首选方法是configuration你的后缀使用一个relayhost,这是由一行

relayhost = smtp.example.com

/etc/postfix/main.cf

然而在OP的情况下,我怀疑这是他的hosting team应该完成的工作