虚拟主机上,怎么用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!";}?>不过目前,我收件箱收到的内容是空的,不知道为什么。 求高手解码 php 加密了 Call to undefined function getInstance()怎么回事 关于die的问题 php如何验证已经登录就不能登录了? PHP 后门分析 在PHP中是用echo输出html语言快,还是嵌入html快? 验证码不能显示,问题大概知道,不知怎么解决? 问一下关于PHP的magic qoutes的小问题 请问如何知道<textarea文本框里的文字有多少行?????例子如下:请高手帮助。 在哪里可以找到 templates ? 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!";
}?>不过目前,我收件箱收到的内容是空的,不知道为什么。