[转]使用php mailer类调用远程SMTP服务器发送邮件Could not execute: /var/qmail/bin/sendmai
2012-03-03 12:01
1111 查看
php mailer 是一款很好用的php电子邮件发送类模块,可以调用本地的smtp发送电子邮件,也可以调用远程的smtp发送电子邮件,但是使用时需要注意一些事项,否则就会造成发送失败,或者根本不能调用的情况,本文就我在使用这个类时,遇到的问题和解决办法进行展开,简要说明一下php mailer的用法,及注意事项。
首先下载phpmailer类库文件,在这里下载,只需一个资源分。 下载地址: http://download.csdn.net/source/2549515
下载之后,将这个文件,即class.phpmailer.php 放到你的工程的某个目录下,在需要发送邮件的地方这样写:
<?php
require 'class.phpmailer.php';
try {
$mail = new PHPMailer(true);
$body = file_get_contents('contents.html'); //邮件的内容写到contents.html页面里了
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.yourdomain.com"; // 远程SMTP服务器
$mail->Username = "yourname@yourdomain.com"; // 远程SMTP 服务器上的用户名
$mail->Password = "yourpassword"; // 你的远程SMTP 服务器上用户对应的密码
//$mail->IsSendmail(); //告诉这个类使用Sendmail组件,使用的时候如果没有sendmail组建就要把这个注释掉,否则会有
“Could not execute: /var/qmail/bin/sendmail ”的错误提示
$mail->AddReplyTo("yourname@yourdomain.com","First Last");
$mail->From = "fromname@yourdomain.com";
$mail->FromName = "First Last";
$to = "toname@domain.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>
注意:上面那个$mail->IsSendmail(); 需要注释掉,否则如果没有sendmail组件的话,会提示 “Could not execute: /var/qmail/bin/sendmail ”的错误!
首先下载phpmailer类库文件,在这里下载,只需一个资源分。 下载地址: http://download.csdn.net/source/2549515
下载之后,将这个文件,即class.phpmailer.php 放到你的工程的某个目录下,在需要发送邮件的地方这样写:
<?php
require 'class.phpmailer.php';
try {
$mail = new PHPMailer(true);
$body = file_get_contents('contents.html'); //邮件的内容写到contents.html页面里了
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.yourdomain.com"; // 远程SMTP服务器
$mail->Username = "yourname@yourdomain.com"; // 远程SMTP 服务器上的用户名
$mail->Password = "yourpassword"; // 你的远程SMTP 服务器上用户对应的密码
//$mail->IsSendmail(); //告诉这个类使用Sendmail组件,使用的时候如果没有sendmail组建就要把这个注释掉,否则会有
“Could not execute: /var/qmail/bin/sendmail ”的错误提示
$mail->AddReplyTo("yourname@yourdomain.com","First Last");
$mail->From = "fromname@yourdomain.com";
$mail->FromName = "First Last";
$to = "toname@domain.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>
注意:上面那个$mail->IsSendmail(); 需要注释掉,否则如果没有sendmail组件的话,会提示 “Could not execute: /var/qmail/bin/sendmail ”的错误!
相关文章推荐
- 使用php mailer类调用远程SMTP服务器发送邮件Could not execute: /var/qmail/bin/sendmai
- php mailer类调用远程SMTP服务器发送邮件实现方法
- php mailer类调用远程SMTP服务器发送邮件实现方法
- 使用php mailer类调用远程SMTP服务器发送邮件
- Ubuntu 使用 heirloom-mail 调用外部邮箱 SMTP 服务器发送邮件
- Ubuntu 使用 heirloom-mail 调用外部邮箱 SMTP 服务器发送邮件
- php使用smtp发送支持附件的邮件示例
- 使用UTL_SMTP发送中文邮件及使用UTL_TCP从附件服务器获取中文附件
- 在PHP中使用Pear 的NetMail发送smtp邮件
- PHP 利用 smtp服务器发送邮件
- 如何在 Linux 上使用 Gmail SMTP 服务器发送邮件通知
- php多种形式发送邮件(mail qmail邮件系统 phpmailer类)
- Wordpress无法发送邮件,基于插件“Contact Form 7”,修改class-phpmailer.php使用SMTP解决。
- 如何在 Linux 上使用 Gmail SMTP 服务器发送邮件通知
- php使用smtp发送邮件报错Cannot connenct to relay host
- 在PHP中使用Pear 的NetMail发送smtp邮件
- php使用pear_smtp发送邮件
- Java调用阿里SMTP服务器实现邮件发送
- php使用pear_smtp发送邮件
- 使用cackPHP发送smtp邮件