我可以让这个功能通过smtp发送电子邮件吗?
function send()
{
if(mail($this->to, $this->subject, $this->body, $this->headers)) return TRUE;
else return FALSE;
}
这是以下代码的一部分:
class sendMail
{
var $to;
var $cc;
var $bcc;
var $subject;
var $from;
var $headers;
var $html;
function sendMail()
{
$this->to = "test@mail.com";
#$this->to = "test@test.com";
$this->cc = NULL;
$this->bcc = NULL;
$this->subject = NULL;
$this->from = NULL;
$this->headers = NULL;
$this->html = FALSE;
}
function getParams($params)
{
$i = 0;
foreach ($params as $key => $value) {
switch($key) {
case 'Submit':
NULL;
break;
default:
if ($key == 'email')
{
$this->from = $value;
$this->subject ="Contactgegevens from " . $value . " at www.webandeve.nl ";
}
$this->body[$i]["key"] = str_replace("_", " ", ucWords(strToLower($key)));
$this->body[$i++]["value"] = $value;
}
}
}
function setHeaders()
{
$this->headers = "From: $this->from\r\n";
if($this->html === TRUE) {
$this->headers.= "MIME-Version: 1.0\r\n";
$this->headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
}
}
function parseBody()
{
$count = count($this->body);
for($i = 0; $i < $count; $i++) {
if($this->html) $content.= "<b>";
$content .= $this->body[$i]["key"].': ';
if($this->html) $content.= "</b>";
if($this->html) $content .= nl2br($this->body[$i]["value"])."\n";
else $content .= $this->body[$i]["value"];
if($this->html) $content.= "<br>\n";
else $content.= "\n".str_repeat("-", 80)."\n";
}
if($this->html) {
$content = "
<style>
BODY {
font-family: verdana;
font-size: 10;
}
</style>
".$content;
}
$this->body = $content;
}
function send()
{
if(mail($this->to, $this->subject, $this->body, $this->headers)) return TRUE;
else return FALSE;
}
function set($key, $value)
{
if($value) $this->$key = $value;
else unset($this->$key);
}
function get_location()
{
return header('Location: thankyou.htm');break;
}
}
我一直在寻找一个简单的解决方案,但找不到任何(我的php知识),但是Git和我脚本的一些完全替代。
答案 0 :(得分:1)
如果要将SMTP邮件配置与mail()
功能一起使用,则需要在php.ini
中设置SMTP配置。
有关详细信息,请参阅E-Mail configuration。
但是我会建议使用像PHPMailer
这样的第三方库