php邮件的smtp配置 [英] smtp configuration for php mail

查看:49
本文介绍了php邮件的smtp配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 php 邮件功能从我的网站发送邮件.但现在它不起作用,我联系了我们的托管团队,然后他们告诉我使用 smtp,因为他们对服务器做了一些更改.我不知道该怎么做.当前代码(带有 php 邮件功能)如下,任何人都可以帮助我了解与此相关的更改.

I am sending mails from my website by using php mail function. But now it is not working and I contacted our hosting team then they told me to use smtp as they did some changes in server. I don't know how to do it. Current code (with php mail function) is as follows, can anyone help me about the changes which I have to do with this.

<?php
$mail_To="someone@gmail.com";
$headers = "";
$headers .= "From: livetv@muscle-tube.com
";
$headers .= "Reply-To: livetv@muscle-tube.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";
$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 邮件包之类的东西.

PHP's mail() function does not have support for SMTP. You're going to need to use something like the PEAR Mail package.

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

Here is a sample SMTP mail script:

<?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>");
}
?>

这篇关于php邮件的smtp配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆