虚拟主机上,怎么用PHP发邮件? 像DISCUZ那样,在虚拟主机都能发邮件怎么弄?和通过SMTP发邮件有区别吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.phpe.net/articles/225.shtml 虚拟主机由很多自定义函数都不支持,我是用mail发邮件关注ing 建议你下载下wordpress,然后看看wp_mail.php文件就知道了Shenzhen Travel 自己的搞定了,用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 loadedrequire_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("[email protected]","First Last");//回复邮箱地址,发送时没什么用。$mail->From = "[email protected]";//发件人地址,需要更改$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("[email protected]", "test");//收件人,需要修改//$mail->AddAttachment("images/phpmailer.gif"); // attachment$mail->IsHTML(true); // send as HTMLif(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo;} else { echo "Message sent!";}?>不过目前,我收件箱收到的内容是空的,不知道为什么。 谁帮写个超链接判断的正则。 新闻数据表为空时,出现mysql_fetch_object(): supplied argument is not a valid MySQL result resource,该如何解决呢? 如果验证邮件是否发送成功 求教PHP中str_replace函数问题 求高手推荐适合新手学习的优秀php整站源码 PHP新手取数据库记录遇到问题 一个非常奇怪的问题 论坛安装成功,但无法发帖? 请教fopen函数的问题,解决马上结贴,谢谢! 新手请教:正则表达式反向引用的疑问 PHP字符换替换问题 链接中写&的原因是什么?
Shenzhen Travel
实现代码大致如下:
<?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("[email protected]","First Last");//回复邮箱地址,发送时没什么用。$mail->From = "[email protected]";//发件人地址,需要更改
$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("[email protected]", "test");//收件人,需要修改//$mail->AddAttachment("images/phpmailer.gif"); // attachment$mail->IsHTML(true); // send as HTMLif(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}?>不过目前,我收件箱收到的内容是空的,不知道为什么。