我用网页运行时正常,能发送,用命令运行php文件时报错,主要代码经检查无误,如下  
  function sendmail($setemail, $setname, $body, $subject) {	require_once(phpmail/phpmailer.php);	$mail = new phpmailer ( true ); // the true param means it will throw exceptions on errors, which we need to catch	$mail->issmtp (); // telling the class to use smtp	try {		$mail->smtpauth = true; // enable smtp authentication		$mail->smtpsecure = sbt_ssl; // sets the prefix to the servier		$mail->host = sbt_smtp_host; // sets gmail as the smtp server		$mail->port = sbt_smtp_port; // set the smtp port for the gmail server		$mail->username = sbt_smtp_user; // gmail username		$mail->password = sbt_smtp_pass; // gmail password		$mail->addreplyto ( sbt_mail_from, sbt_mail_from_name );		$mail->addaddress ( $setemail, $setname );		$mail->setfrom (sbt_smtp_user,sbt_smtp_user); //sender name		$mail->subject = $subject;				$mail->msghtml ( $body );				if (! $mail->send ()) {//(这边没报错)			echo message could not be sent. ;			echo mailer error:  . $mail->errorinfo;			exit ();		} 	} catch ( phpmailerexception $e ) {		echo $e->errormessage (); //pretty error messages from phpmailer(就是这边输出错误的)	} catch ( exception $e ) {		echo $e->getmessage (); //boring error messages from anything else!	}}
问下是什么原因,目的是为了可以用linux计划任务来执行该php文件
回复讨论(解决方案)   我用的是gmail邮箱,465  $mail->host =smtp.gmail.com; $mail->port =465
错误代码呢? 
   smtp error: could not connect to smtp host,问题题目就是啊 
   截图了,不知道能不能上传,我试下啊[img=http://hi.csdn.net/space-48606-do-album-picid-730173-goto-down.html][/img] 
   这次好了吧! 
   估计就是扩展的问题,用命令行就会出现这个扩展那个扩展的问题
opensll扩展开了么?呵呵,应该开了吧,不开的话网页发送不会成功 
   确认这个文件能独立运行? 
   刚刚测试了一下,网页好使,命令行不好使,报错:说扩展php_pdo_mysql.dll找不到 
   当然可以独立运行,我代码又没全部贴出来,如果不发邮件,输出些文字,是没有问题的 
   扩展我开了的 
   php --ini 一下,看使用的ini是否和作为apache模块运行的php一致. 
   实在不行,我安装个linux环境来测试吧!  
 看网上说这个问题是php.ini没配好,我看了下,配的是smtp,照他们说的改了也没用,关键是我smtp已经重新赋值,用gmail邮箱的服务器的啦 
   linux上不会出现这个问题的 
   php --ini 一下,看使用的ini是否和作为apache模块运行的php一致.  
 老虎头,能不能说详细点,修改ini文件吗?你看这样行不?  
  [mail function]; for win32 only.smtp = localhostsmtp_port = 25; for win32 only.sendmail_from = me@example.com; for unix only.  you may supply arguments as well (default: sendmail -t -i).;sendmail_path = /usr/sbin/sendmail -t -i; force the addition of the specified parameters to be passed as extra parameters; to the sendmail binary. these parameters will always replace the value of; the 5th parameter to mail(), even in safe mode.;mail.force_extra_parameters =
引用 11 楼 foolbirdflyfirst 的回复:
php --ini 一下,看使用的ini是否和作为apache模块运行的php一致.
老虎头,能不能说详细点,修改ini文件吗?你看这样行不?  
 php code
[mail function]  
 ; for win32 only.  
 smtp = localhost  
 smtp_port = 25
; for win32 ……  
 嗯,我没说清楚,我说的是命令php --ini,看cli下运行的php和apache模块运行的php是否公用一个ini文件  
 有时候phpcli单独安装的话会自带一个ini文件.
linux上不会出现这个问题的  
 大哥,你对linux很熟吗?那问下像我这样 require_once(phpmail/phpmailer.php); 载入了phpmailer能行不?我怕linux不接受phpmailer插件
老虎头,请帮我看看呢!  
  c:\wamp\bin\php\php5.2.6>php --iniconfiguration file (php.ini) path: c:\windowsloaded configuration file:         c:\wamp\bin\php\php5.2.6\php.iniscan for additional .ini files in: (none)additional .ini files parsed:      (none)
不可能,$mail->issmtp ();这个表明你已经设置了smtp发送了.  
 你现在的主要问题是找找看为什么socket连接不了smtp服务器.  
 防火墙也有可能. 
   老虎头,你说对了,不一致唉,怎么改? 
   loaded configuration file:         c:\wamp\bin\php\php5.2.6\php.ini  
 这个php.ini不是我目前运行的那个php.ini 
   wamp环境,应该是共用一份ini文件的.想再一次确定的话,php网页输出phpinfo(),看使用的ini文件,是否和这个一致.  
 命令:telnet smtp.gmail.com 465 ,确定能连接成功? 
   老虎头,你说对了,不一致唉,怎么改?  
 good  
 那么就使用php -c 命令引入你的正确ini路径  
  php -c ini路径 php文件
具体可以php -help查看命令参数
学习围观 
   检查一下防火墙,另外再检查一下发送图片附件的代码 
   wamp环境,应该是共用一份ini文件的.想再一次确定的话,php网页输出phpinfo(),看使用的ini文件,是否和这个一致.  
 命令:telnet smtp.gmail.com 465 ,确定能连接成功?  
 telnet smtp.gmail.com 465不能连接,那我应该用什么邮件服务器呢? 
   telnet都不行,肯定是你防火墙禁止了访问  
   谢谢大家,解决了,首先是防火墙的问题,360防火墙忘关了,其次是ini问题 
   to  rxpy2007  
 php.ini什么问题,请说清楚些,我也遇到这个问题了,linux环境 
   希望楼主说的清楚点,怎么解决的,我的win环境也出现了一下问题  
 ! 
   gmail注册的是企业版的吗 
   [quote=引用 14 楼 rxpy2007 的回复:]
引用 11 楼 foolbirdflyfirst 的回复:
php --ini 一下,看使用的ini是否和作为apache模块运行的php一致.
老虎头,能不能说详细点,修改ini文件吗?你看这样行不?  
 php code
[mail function]  
 ; for win32 only.  
 smtp = localhost  
 smtp_port = 25
; for win32 ……  
 嗯,我没说清楚,我说的是命令php --ini,看cli下运行的php和apache模块运行的php是否公用一个ini文件  
 有时候phpcli单独安装的话会自带一个ini文件.  
   请问php --ini怎么用
   
 
   