虚拟主机上,怎么用PHP发邮件?

codeyell-com 2009-08-20 11:18:05
像DISCUZ那样,在虚拟主机都能发邮件
怎么弄?
和通过SMTP发邮件有区别吗?
...全文
338 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
codeyell-com 2009-08-20
  • 打赏
  • 举报
回复
http://www.phpe.net/articles/225.shtml
codeyell-com 2009-08-20
  • 打赏
  • 举报
回复
自己的搞定了,用phpmailer做的
实现代码大致如下:
<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once("class.phpmailer.php");
// optional, gets called from within class.phpmailer.php if not already loaded
require_once("class.smtp.php");

$mail = new PHPMailer();

$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
// sets the prefix to the servier,如果是gmail需要开启ssl并修改smtp和端口
//$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.163.com"; // sets 163 as the SMTP server
$mail->Port = 25; // set the SMTP port for the 163 server

$mail->Username = "xxxx"; // 163 username 163帐户的用户名,需要与前面的smtp对应
$mail->Password = "xxxx"; // 163 password 163帐户密码,与前面对应

$mail->AddReplyTo("baiyuxiong@163.com","First Last");//回复邮箱地址,发送时没什么用。

$mail->From = "baiyuxiong@163.com";//发件人地址,需要更改
$mail->FromName = "xxx"; //发件人名称

$mail->Subject = "test";

$mail->Body = "testtesttest"; //HTML Body,内容,
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
// optional, comment out and test
$mail->AltBody ="text/html";
$mail->WordWrap = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddAddress("xxxx@gmail.com", "test");//收件人,需要修改

//$mail->AddAttachment("images/phpmailer.gif"); // attachment

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

?>

不过目前,我收件箱收到的内容是空的,不知道为什么。
pigchan 2009-08-20
  • 打赏
  • 举报
回复
学习一下,多谢楼上
kaixin110 2009-08-20
  • 打赏
  • 举报
回复
建议你下载下wordpress,然后看看wp_mail.php文件就知道了
Shenzhen Travel
mlsml 2009-08-20
  • 打赏
  • 举报
回复
虚拟主机由很多自定义函数都不支持,我是用mail发邮件。。。关注ing
codeyell-com 2009-08-20
  • 打赏
  • 举报
回复
up

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧