PHP PEAR 邮件的问题

2022-08-30 22:34:43

我正在尝试使用 PEAR 邮件通过外部 SMTP 服务器发送。它似乎挂起了一会儿,然后脚本结束了。它输出我所有的“echo”语句,直到发送后的那一个。没有任何东西输出超过显示“发送前”的回声。谁能告诉我这里可能出了什么问题?(虚拟值替换为 smtp 值)。未发送邮件。感谢您的帮助!

echo "start";
$n = $_POST['txtName'];
$e = $_POST['txtEmail'];
$t = 'Kenny <email@host.com>';
$f = 'Kenny <email@host.com>';
$s = 'CPA TEST';
$b = "name: $n email: $e"; 

include("mail.php");
echo "after include";
/* mail setup recipients, subject etc */
$recipients = $t;
$headers["From"] = $f;
$headers["To"] = $t;
$headers["Subject"] = $s;
$mailmsg = $b;
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "my_smtp_host";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "my_email";
$smtpinfo["password"] = "my_password";
echo "before object";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
echo "before send";
/* Ok send mail */
$send = $mail_object->send($recipients, $headers, $mailmsg);
echo "after send";
if (PEAR::isError($send)) { print($send->getMessage());}else{print "end";} 
echo "done";

答案 1

如果有人在Linux上运行并遇到与Jayme相同的问题。下面是安装缺少的“Net/”类的另一种简单解决方案。这些缺少的类会导致脚本中断。

sudo pear install Net_SMTP


答案 2

我遇到了相同的问题,它挂在发送命令上。我的第一步是从命令行运行以查看完整的错误消息(如上面的Rap建议)。

php mymailsample.php

它吐出以下内容

Warning:  include_once(Net/SMTP.php): failed to open stream: No such file or directory in mail/Mail/smtp.php on line 348
PHP Warning:  include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/lib/php') in mail/Mail/smtp.php on line 348
PHP Fatal error:  Class 'Net_SMTP' not found inmail/Mail/smtp.php on line 349

我下载了以下内容,并将它们放在/Net中


http://pear.php.net/package/Net_SMTP/download http://pear.php.net/package/Net_Socket/download

我必须调整SMTP和套接字库的权限,以便Apache可以读取它们。

瞧,它奏效了!


推荐