我用网页运行时正常,能发送,用命令运行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. <p>";			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!	}}
                        
                        这是一款可爱的 happy birthday to you 字母矢量素材,提供了 AI 和 EPS 和免扣 PNG 等格式,含 JPG 预览图。
                                8
                            
                        
                    我用的是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文件
  
 学习围观 
检查一下防火墙,另外再检查一下发送图片附件的代码
  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怎么用 
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号