php收发邮件

  • 内容
  • 评论
  • 相关

[code lang="php" start="" highlight=""]
IsSMTP();
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->CharSet ="GB2312";
$mail->Encoding = "base64";
// 以下设置 - 不要更改!
$mail->AddAddress($to, "");
$mail->Subject = $subject;
$mail->Body = $content;
// 以下 5 个变量值必须据实修改
$host = '61.183.41.172';
$username = 'admin@php95.com';
$password = '******';
$from = 'admin@php95.com';
$fromname = '天马博客';
//$mail->AddReplyTo("", "");
//$mail->AddAttachment("ok.jpg"); //附件
// 以下设置 - 不要更改!
$mail->Host = $host;
$mail->Username = $username;
$mail->Password = $password;
$mail->From = $from;
$mail->FromName = $fromname;
// 发送并返回相应信息
if(!$mail->Send()){ return 0; exit(); }
return 1;
}

?>

[/code]

[code lang="html" start="" highlight=""]
<form action="" method="post" name="f_sendmail" id="f_sendmail">
<input name="t_from" type="text" disabled="disabled" id="t_from" value="admin@php95.com" />
发件人
<p>
<input name="t_to" type="text" id="t_to" />
收件人<p><input name="b_sendmail" type="submit" id="b_sendmail" value=" 发 送 " />
</form>

 

[/code]

[code lang="" start="" highlight=""]
/**先设置 $to $subject $content 这三个变量的值
再调用 sendmail 函数来发送邮件
**/
if($_POST[b_sendmail]){
$to = htmlspecialchars(addslashes($_POST[t_to]));
$subject = '天马博客:一封测试邮件↖(^ω^)↗';
$content = '恭喜你,你已看到了PHP发送邮件的效果。 -- 天马博客';
if(sendmail($to,$subject,$content)) {
echo "发送到 $to 的邮件已成功!";
}else{
echo '发送失败!';
}
}
?>
[/code]

评论

1条评论
  1. Ordinary

    Gosh, I wish I would have had that initfmaoron earlier!