smtp配置为php邮件 [英] smtp configuration for php mail
本文介绍了smtp配置为php邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过使用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 wchich I have to do with this.
<?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邮件包的内容。
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>");
}
?>
这篇关于smtp配置为php邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文