PHP PEAR 邮件的问题

发布于 2024-08-21 22:30:16 字数 1339 浏览 2 评论 0原文

我正在尝试使用 PEAR Mail 通过外部 smtp 服务器发送。似乎挂起了一段时间,然后脚本就结束了。它输出我所有的“echo”语句,直到发送后的语句。在显示“发送之前”的回显之后,不会输出任何内容。谁能告诉我这里可能出了什么问题? (虚拟值替代 smtp 值)。邮件未发送。感谢您的帮助!

echo "start";
$n = $_POST['txtName'];
$e = $_POST['txtEmail'];
$t = 'Kenny <[email protected]>';
$f = 'Kenny <[email protected]>';
$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";

I am trying to use PEAR Mail to send using an external smtp server. It seems to hang for a while, then the script ends. It outputs all of my "echo" statements up till the one after the send. Nothing is output past the echo that says "before send". Can anyone tell me what might be wrong here? (dummy values substituted for smtp values). Mail is not being sent. Thanks for helping!

echo "start";
$n = $_POST['txtName'];
$e = $_POST['txtEmail'];
$t = 'Kenny <[email protected]>';
$f = 'Kenny <[email protected]>';
$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";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

谎言 2024-08-28 22:30:16

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

sudo pear install Net_SMTP

If someone is running on linux and runs into the same problem as Jayme. Here is another simple solution for installing the missing "Net/" classes. These missing classes causes the script to interrupt.

sudo pear install Net_SMTP

把人绕傻吧 2024-08-28 22:30:16

我遇到了同样的问题,它挂在发送命令上。我的第一步是从命令行运行以查看完整的错误消息(如 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/下载
http://pear.php.net/package/Net_Socket/download

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

瞧,它成功了!

I ran into the same issue where it hung on the send command. My first step was to run from the command line to see the full error message (as Rap suggested above).

php mymailsample.php

It spit out the following

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

I downloaded the following, and put them in /Net

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

I had to adjust the permissions of the SMTP and Socket libraries so they could be read by Apache.

And voila, it worked!

美煞众生 2024-08-28 22:30:16

尝试此操作以确保您的邮件正常工作:

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

如果这不起作用,那么您将需要检查您的 PHP 配置。

请参阅http://php.net/manual/en/function.mail.php 了解更多信息。

Try this to ensure your mail is working:

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

If this does not work then you will need to check your PHP Configuration.

See http://php.net/manual/en/function.mail.php for more information.

淡忘如思 2024-08-28 22:30:16

重新安装channel://pear.php.net/Mail-1.2.0对我不起作用。(Ubuntu 12.04)

只需删除字符“&”新之前

sudo vi /usr/share/php/Mail/smtp.php
    349         /*$this->_smtp = &new Net_SMTP($this->host, */
    350         $this->_smtp = new Net_SMTP($this->host,

The reinstall of channel://pear.php.net/Mail-1.2.0 does'nt work for me.(Ubuntu 12.04)

Just remove the caracter "&" before new

sudo vi /usr/share/php/Mail/smtp.php
    349         /*$this->_smtp = &new Net_SMTP($this->host, */
    350         $this->_smtp = new Net_SMTP($this->host,
走过海棠暮 2024-08-28 22:30:16

Todd 的脚本非常出色,但无法解决您的问题,即您的浏览器在 SMTP 之前超时。这就是为什么您只能看到页面的一半,并且看不到任何可用于调试 SMTP 设置的错误消息。

解决办法是直接运行PHP脚本。没有超时。

如果由于 ISP 不提供 shell 访问权限而无法执行此操作,请创建一个每分钟运行一次的 cron 作业。 Cron 会将输出通过电子邮件发送给您,其中包含完整的调试详细信息。

Todd's script is excellent, but will not solve your problem which is that your browser times out before the SMTP does. That is why you only see half your page and are not seeing any error messages that you can use to debug your SMTP settings.

The solution is to run the PHP script directly. No timeout.

If you can't do that because your ISP doesn't give you shell access, create a cron job to run every minute. Cron will email the output to you which will have full debug details.

戒ㄋ 2024-08-28 22:30:16

对于 PHP 版本 7,您需要安装 php-net-smtp:

sudo apt-get update
sudo apt-get install php-net-smtp

For Php version 7 you need to install php-net-smtp:

sudo apt-get update
sudo apt-get install php-net-smtp
孤单情人 2024-08-28 22:30:16

我实际上也遇到过同样的问题。一个制作脚本出现故障,我经历了最困难的故障排除过程。主要是因为有太多代码阻止了错误的出现。最终,我使用了 Kenny Ray 的代码,对其进行了修改以适合我的环境,并运行了测试。事实证明 Net_Socket 莫名其妙地消失了。我已卸载并重新安装它,一切又开始工作了。我希望这对你有帮助。

I've actually encountered the same problem. A production script broke down, and I had the hardest time troubleshooting it. Mainly because there was so much code that prevented errors from showing up. Ultimately, I used Kenny Ray's code, modified it to work for my environment, and ran a test. It turned out the Net_Socket somehow disappeared. I've uninstalled and re-installed it, and everything started working again. I hope this helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文